Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Data Trigger to Conditionally format a text block
    text
    copied!<p>I need to conditionally change a TextBlock binding based on the value of an object which is one of many in an OC in my ViewModel. Im sure I need to use DataTriggers to accomplish this. Specifically I want to dynamically change the property that the first TexBlock below binds to for its Text Property. The OC Summary contains a collection of Name objects and each object has a Property called NameType. If NameType = 1 I want to bind to Name1, NameType=2 bind to Name2 etc. The second TextBlock is fine the way it is as it shows an associated value.</p> <pre><code> &lt;ItemsControl Grid.Row="1" ItemsSource="{Binding Summary}" Margin="0,3,0,0"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Style="{StaticResource TooltipLeftColumnTextStyle}" Text="{Binding Name}" /&gt; &lt;TextBlock Style="{StaticResource TooltipRightColumnTextStyle}" Text="{Binding Value}" /&gt; &lt;Border Grid.Row="1" Style="{StaticResource TooltipSeparatorBorder}" /&gt; &lt;Border Grid.Row="2" Style="{StaticResource TooltipSeparatorAlternateBorder}" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload