locked
How could I programmatically make a formula in RichTextBlock

    Question

  • Dear james,

          sorry still facing the problem

                string statement= "What will come in place of the question mark (?) in the following questions?  <img  src='Apti_1_PO-fig002.png'/>  X  <img src='Apti_1_PO-fig003.png'/> ÷ <img  src='Apti_1_PO-fig004.png'/> + <img  src='Apti_1_PO-fig005.png'/> =?"
                richtextbox.Blocks.Clear();
                InlineUIContainer a = new InlineUIContainer();
                var paragraph = new Paragraph();
                int stackpos = 1;
                var stackpanel = new StackPanel();
                stackpanel.Orientation = Orientation.Horizontal;
                    
                // a1 = new InlineUIContainer();
                startcheckdisplay:
    
                if(statement.Contains("<img src"))
                {
                    int startpoint = statement.IndexOf("<img src");
                    int endpoint = statement.IndexOf("'/>")+3;
                    string imagefullsource = statement.Substring(startpoint, (endpoint - startpoint));
    
                    imagefullsource = imagefullsource.Replace("<img src='", "");
                    imagefullsource = imagefullsource.Replace("'/>", "");
                    
                    Image webimage = new Image();
                    webimage.Source = new BitmapImage(new Uri(imagefullsource));
                    webimage.Height = webimage.Height;
                    webimage.Width = webimage.Width;
                    string beforeimage = statement.Substring(0, startpoint);
                    webimage.Stretch = Stretch.None;
                    stackpanel.Children.Insert(stackpos, webimage);
                    stackpos += 1;
                    webimage.Stretch = Stretch.None;
                    
                    paragraph.Inlines.Add(new Run() { Text = beforeimage });
                    statement = statement.Substring((endpoint), statement.Length-endpoint);
                    goto startcheckdisplay; 
                }
    
                a.Child = stackpanel;
                paragraph.Inlines.Add(a);
                paragraph.Inlines.Add(new Run() { Text = statement });
                richtextbox.Blocks.Add(paragraph);

    i believe now understand my full code


    Thursday, October 09, 2014 9:25 AM

Answers

  • Hi Mann,

    I split the question because your previous question has been solved, and the problem you are facing now is you probably don't know how to manage your code.

    To make your code works fine, here I have some tips, you insert all the image to the stackpanel but you did not insert "X" "/" "+" "- " inside, that's why your formula looks bad.

            public void method()
            {
                string statement = "What will come in place of the question mark (?) in the following questions?  <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/>  X  <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> ÷ <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> + <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> =?";
                richtextblock.Blocks.Clear();
                InlineUIContainer a = new InlineUIContainer();
                var paragraph = new Paragraph();
                int stackpos = 1;
                var stackpanel = new StackPanel();
                stackpanel.Orientation = Orientation.Horizontal;
                    
                // a1 = new InlineUIContainer();
                startcheckdisplay:
    
                if(statement.Contains("<img src"))
                {
                    int startpoint = statement.IndexOf("<img src");
                    int endpoint = statement.IndexOf("'/>")+3;
                    string imagefullsource = statement.Substring(startpoint, (endpoint - startpoint));
    
                    imagefullsource = imagefullsource.Replace("<img src='", "");
                    imagefullsource = imagefullsource.Replace("'/>", "");
                    
                    Image webimage = new Image();
                    webimage.Source = new BitmapImage(new Uri(imagefullsource));
                    webimage.Height = webimage.Height;
                    webimage.Width = webimage.Width;
    
    
    
                    string beforeimage = statement.Substring(0, startpoint);
                    webimage.Stretch = Stretch.None;
                    TextBlock beforeimageText = new TextBlock() { Text = beforeimage };
                    stackpanel.Children.Add(beforeimageText);
                    stackpanel.Children.Add(webimage);
                    //stackpanel.Children.Insert(stackpos, webimage);
                    
                    //stackpos += 1;
                    webimage.Stretch = Stretch.None;
                    
                    //paragraph.Inlines.Add(new Run() { Text = beforeimage });
                    statement = statement.Substring((endpoint), statement.Length-endpoint);
                    goto startcheckdisplay; 
                }
    
                a.Child = stackpanel;
                paragraph.Inlines.Add(a);
                paragraph.Inlines.Add(new Run() { Text = statement });
                richtextblock.Blocks.Add(paragraph);
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by mann madhan1 Monday, October 13, 2014 4:50 PM
    Saturday, October 11, 2014 9:36 AM
    Moderator

All replies

  • Thanks for your code, it help me understand your question. 

    Looks like you are splitting the statement string into texts and images, simply read from your code, i don't think your webimage URI is correct, if you are saving the image in the local folder, you should at least use "ms-appx" as prefix. 

    Let's narrow down the question, set a breakpoint in this line

    webimage.Source = new BitmapImage(new Uri(imagefullsource));

    Could you validate if you can generate a correct imagefullsource and you can have your webimage? 

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, October 09, 2014 3:25 PM
    Moderator
  • sorry james. i delete my url path. but the path is correct. when i am running application my result is 

    here the marked is (4) images. 

    Thursday, October 09, 2014 5:35 PM
  • Dear team,

                      please some body to help me.

    Friday, October 10, 2014 6:12 PM
  • Hi Mann,

    I split the question because your previous question has been solved, and the problem you are facing now is you probably don't know how to manage your code.

    To make your code works fine, here I have some tips, you insert all the image to the stackpanel but you did not insert "X" "/" "+" "- " inside, that's why your formula looks bad.

            public void method()
            {
                string statement = "What will come in place of the question mark (?) in the following questions?  <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/>  X  <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> ÷ <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> + <img src='http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png'/> =?";
                richtextblock.Blocks.Clear();
                InlineUIContainer a = new InlineUIContainer();
                var paragraph = new Paragraph();
                int stackpos = 1;
                var stackpanel = new StackPanel();
                stackpanel.Orientation = Orientation.Horizontal;
                    
                // a1 = new InlineUIContainer();
                startcheckdisplay:
    
                if(statement.Contains("<img src"))
                {
                    int startpoint = statement.IndexOf("<img src");
                    int endpoint = statement.IndexOf("'/>")+3;
                    string imagefullsource = statement.Substring(startpoint, (endpoint - startpoint));
    
                    imagefullsource = imagefullsource.Replace("<img src='", "");
                    imagefullsource = imagefullsource.Replace("'/>", "");
                    
                    Image webimage = new Image();
                    webimage.Source = new BitmapImage(new Uri(imagefullsource));
                    webimage.Height = webimage.Height;
                    webimage.Width = webimage.Width;
    
    
    
                    string beforeimage = statement.Substring(0, startpoint);
                    webimage.Stretch = Stretch.None;
                    TextBlock beforeimageText = new TextBlock() { Text = beforeimage };
                    stackpanel.Children.Add(beforeimageText);
                    stackpanel.Children.Add(webimage);
                    //stackpanel.Children.Insert(stackpos, webimage);
                    
                    //stackpos += 1;
                    webimage.Stretch = Stretch.None;
                    
                    //paragraph.Inlines.Add(new Run() { Text = beforeimage });
                    statement = statement.Substring((endpoint), statement.Length-endpoint);
                    goto startcheckdisplay; 
                }
    
                a.Child = stackpanel;
                paragraph.Inlines.Add(a);
                paragraph.Inlines.Add(new Run() { Text = statement });
                richtextblock.Blocks.Add(paragraph);
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by mann madhan1 Monday, October 13, 2014 4:50 PM
    Saturday, October 11, 2014 9:36 AM
    Moderator
  • Thanks james
    Saturday, October 11, 2014 10:36 AM