I have a Window with a ListBox
which has a DataTemplate
, bound to an ObservableCollection
of LogItems
. The ItemsSource
of the ListBox
is set in code to the collection; the bindings on the TextBox
and TextBlock
which make up the DataTemplate
are set in XAML. So far, so conventional. However, I need to set the font size/family for the TextBlock
at runtime. Currently this information is held in a static cGlobals class. So I need to be able to bind the TextBlock.Text
to the LogItems
collection, but the TextBlock.FontSize
property to the cGlobals.LogFontSize
property. How can I do this, either via binding as sketched out in the XAML below, or in code?
<ListBox . . . . >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" . . . . >
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="*" MinHeight="40" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Background="Honeydew" Text="{Binding Mode=OneWay, Path=Header, . . . . />
<TextBlock FontSize="{Binding ??????}" Grid.Row="1" Text="{Binding Path=BodyText}" />
</Grid>
</DataTemplate >
</ListBox.ItemTemplate >
</ListBox>