Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataTemplate.Triggers vs Style.Triggers

$
0
0

In order to change foreground color of ListBoxItem base on condition, I can do inside DataTemplate.Triggers:

<ListBox.ItemTemplate>
    <DataTemplate>
        ...
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Name}" Value="Item1">
                <Setter Property="ListBoxItem.Foreground" Value="Blue" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ListBox.ItemTemplate>

Or inside ItemContainerStyle:

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Name}" Value="Item1">
                <Setter Property="Foreground" Value="Blue" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListBox.ItemContainerStyle>

I wonder what's the difference between DataTemplate.Triggers and Style.Triggers? Which one happen first? Most importantly, what's the semantic meaning of each trigger group?




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>