<
WrapPanel
Margin
=
"10"
>
TextBlock
"0,0,4,0"
Text
"This is an example"
/>
"with textboxes that line up horizontally"
"then wrap by TEXTBLOCK to a new"
"line when there is no more space"
"pull the window out to"
"see it wrap and change"
</
TextWrapping
"Wrap"
><
Run
/><
" of a group of"
" manually coded runs"
" which are parts of a textblock"
" and this is probably closer to what you want"
/></
var texts =
new
List<
string
> {
"This is an example of building a TextBlock"
,
" programmatically from a collection"
" of strings into one flexible wrapping TextBlock"
};
foreach
(var text
in
texts)
tb1.Inlines.Add(
Run { Text = text });
var cm1 =
ContextMenu();
cm1.Items.Add(
MenuItem { Header =
"Copy"
});
var cm2 =
cm2.Items.Add(
"Do something else"
var run1 =
{
Text =
"Hello"
Background = Brushes.Yellow,
Foreground = Brushes.Blue,
Cursor = Cursors.Hand,
ContextMenu = cm1,
FlowDirection = System.Windows.FlowDirection.RightToLeft,
FontFamily =
FontFamily(
"Courier"
),
FontSize = 20.0D,
FontWeight = FontWeights.Bold,
TextDecorations = TextDecorations.Strikethrough,
ToolTip =
"Run 1"
run1.MouseLeftButtonDown +=
MouseButtonEventHandler(run1_MouseLeftButtonDown);
var run2 =
" World"
Background = Brushes.LightGreen,
Foreground = Brushes.Red,
Cursor = Cursors.Cross,
ContextMenu = cm2,
FlowDirection = System.Windows.FlowDirection.LeftToRight,
"Times New Roman"
FontSize = 30.0D,
FontWeight = FontWeights.ExtraLight,
TextDecorations = TextDecorations.Underline,
"Run 2"
run2.MouseLeftButtonDown +=
MouseButtonEventHandler(run2_MouseLeftButtonDown);
var tb2 =
TextBlock { Margin =
Thickness(10) };
tb2.Inlines.Add(run1);
tb2.Inlines.Add(run2);
sp1.Children.Add(tb2);