Answered by:
add multiple paragraphs in single line (InlineUIContainer)

Question
-
Dear team,
i am developing a windows store application which contains image and text so i use RichTextBlock to display the image and text.
the code i used
startcheckdisplay: if(statement.Contains("imgstart")) { var paragraph = new Paragraph(); a = new InlineUIContainer(); int startpoint = statement.IndexOf("imgstart"); int endpoint = statement.IndexOf("imgend")+6; string imagefullsource = statement.Substring(startpoint, (endpoint - startpoint)); 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; a.Child = webimage; paragraph.Inlines.Add(new Run() { Text = beforeimage }); paragraph.Inlines.Add(a); statement = statement.Substring((endpoint), statement.Length-endpoint); richtextbox.Blocks.Add(paragraph); goto startcheckdisplay; }
for each instance it starts new line.
kindly help me
- Edited by mann madhan1 Wednesday, October 8, 2014 7:59 PM
- Moved by Jamles HezModerator Thursday, October 9, 2014 4:25 PM from ui design
Wednesday, October 8, 2014 7:56 PM
Answers
-
As you can see from the documentation: Child property, Child property only accept a single UIElement, for this reason, you cannot add mutiple images as the child of the InlineUIContainer.
But you could put the images into a StackPanel by setting its orientation as vertical and let the StackPanel be the child of InlineUIContainer.
--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 Thursday, October 9, 2014 5:26 AM
Thursday, October 9, 2014 5:12 AMModerator -
It's easy, take a look at the code:
var paragraph = new Paragraph(); var inline = new InlineUIContainer(); var stackpanel = new StackPanel(); stackpanel.Orientation = Orientation.Horizontal; for (int i = 0; i < 3; i++) { Image webimage = new Image(); webimage.Source = new BitmapImage(new Uri("http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png")); webimage.Height = 18; webimage.Width = 85; stackpanel.Children.Add(webimage); } //webimage.Stretch = Stretch.None; inline.Child = stackpanel; paragraph.Inlines.Add(new Run() { Text = "beforeimage" }); paragraph.Inlines.Add(new Run() { Text = "111111111beforeimage" }); paragraph.Inlines.Add(inline); //statement = statement.Substring((endpoint), statement.Length - endpoint); richtextblock.Blocks.Add(paragraph);
And here is the screenshot
--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.- Proposed as answer by Jamles HezModerator Thursday, October 9, 2014 5:37 AM
- Marked as answer by mann madhan1 Thursday, October 9, 2014 6:11 AM
Thursday, October 9, 2014 5:36 AMModerator
All replies
-
Hi mann,
I cannot reproduce the issue, here is my code:
var paragraph = new Paragraph(); Image webimage = new Image(); webimage.Source = new BitmapImage(new Uri("http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png")); webimage.Height = 18; webimage.Width = 85; var a = new InlineUIContainer(); //webimage.Stretch = Stretch.None; a.Child = webimage; paragraph.Inlines.Add(new Run() { Text = "beforeimage" }); paragraph.Inlines.Add(new Run() { Text = "111111111beforeimage" }); paragraph.Inlines.Add(a); //statement = statement.Substring((endpoint), statement.Length - endpoint); richtextblock.Blocks.Add(paragraph);
I don't know what is your statement means here, but my code looks fine
--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 9, 2014 3:28 AMModerator -
Thanks james,
i have multiple images (it is dynamic so i don't know the count of images). how can i load the image using the same instance (a.child)
kindly help
Thursday, October 9, 2014 5:08 AM -
As you can see from the documentation: Child property, Child property only accept a single UIElement, for this reason, you cannot add mutiple images as the child of the InlineUIContainer.
But you could put the images into a StackPanel by setting its orientation as vertical and let the StackPanel be the child of InlineUIContainer.
--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 Thursday, October 9, 2014 5:26 AM
Thursday, October 9, 2014 5:12 AMModerator -
Thanks james,
i am new to xaml can you provide a sample code.. please
Thursday, October 9, 2014 5:26 AM -
It's easy, take a look at the code:
var paragraph = new Paragraph(); var inline = new InlineUIContainer(); var stackpanel = new StackPanel(); stackpanel.Orientation = Orientation.Horizontal; for (int i = 0; i < 3; i++) { Image webimage = new Image(); webimage.Source = new BitmapImage(new Uri("http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png")); webimage.Height = 18; webimage.Width = 85; stackpanel.Children.Add(webimage); } //webimage.Stretch = Stretch.None; inline.Child = stackpanel; paragraph.Inlines.Add(new Run() { Text = "beforeimage" }); paragraph.Inlines.Add(new Run() { Text = "111111111beforeimage" }); paragraph.Inlines.Add(inline); //statement = statement.Substring((endpoint), statement.Length - endpoint); richtextblock.Blocks.Add(paragraph);
And here is the screenshot
--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.- Proposed as answer by Jamles HezModerator Thursday, October 9, 2014 5:37 AM
- Marked as answer by mann madhan1 Thursday, October 9, 2014 6:11 AM
Thursday, October 9, 2014 5:36 AMModerator -
Dear james,
sorry for torturing your
the above code works super but my requirement is insert the image in the particular position
eg:
What will come in place of the question mark (?) in the following questions?
+ 25 - 42 X
=?
Thanks again
(it is dynamic question so the location of the image and number of images will change) i have found the location of the image but i don't how to insert the image in a particular position
- Edited by mann madhan1 Thursday, October 9, 2014 7:04 AM
Thursday, October 9, 2014 7:00 AM -
Alright, How about insert in the certain place in StackPanel? use StackPanel.Children.Insert(number,UIElement);
var inline = new InlineUIContainer(); var stackpanel = new StackPanel(); stackpanel.Orientation = Orientation.Horizontal; stackpanel.Children.Add(new TextBlock() { Text = "1111" }); stackpanel.Children.Add(new TextBlock() { Text = "2222" }); stackpanel.Children.Add(new TextBlock() { Text = "3333" }); for (int i = 0; i < 1; i++) { Image webimage = new Image(); webimage.Source = new BitmapImage(new Uri("http://i.msdn.microsoft.com/Areas/Centers/Themes/StandardDevCenter/Content/Images/microsoftLogoForHeader.png")); webimage.Height = 18; webimage.Width = 85; stackpanel.Children.Insert(1, 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 9, 2014 8:30 AMModerator