1
<ListBox ItemsSource="{Binding Customers}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="1" x:Name="BackgroundGrid">
<TextBlock Text="{Binding CustomerName}" />
<TextBlock Text="{Binding CustomerId}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding CustomerId}" Value="9-3453"><Setter TargetName="BackgroundGrid" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在上面的代碼中,我需要提供基於屬性值的DataTrigger值而不是硬編碼值。如何將樣式應用於列表框項目基於WPF中的屬性值
由於提前, 迪內希
嘗試使用MultiBinding與值轉換器。你可以在這裏找到一個例子:https://social.msdn.microsoft.com/Forums/de-DE/729d2ac8-67db-4ab2-856b-8d56a9992bc5/datatrigger-binding-in-value?forum=wpf – MarkusE
你需要在樣式中設置背景,這是一個優先問題 – nkoniishvt