本文介绍了WPF:一些组合框项目更改背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变某些项目的背景中符合条件的组合框
I'm trying to change the background of certain items in a combobox that meet a condition
<ComboBox ItemsSource="{Binding Path=Model.Names, Mode=OneWay}" SelectedValue="{Binding Path=SelectedCompanyName}" DisplayMemberPath="Alias" />
的事情是,别名被保存在两个不同的地方(在公司和顺序)和。如果他们不配合,我们想突出这个
The thing is that "Alias" is saved in two different places (in company and in order) and if they dont match we want to highlight this.
我想要做这样的事情:
<Style>... <DataTrigger Binding="{Binding Path=isMismatch}" Value="True> <Setter Property="Background" Value="Red" />...任何帮助表示赞赏。
推荐答案您需要创建这样的自定义数据模板:
You need to create custom data template like this:
<ComboBox Width="300" Height="30" ItemsSource="{Binding Path=Model.Names, Mode=OneWay}"> <ComboBox.ItemTemplate> <DataTemplate> <Grid x:Name="templateGrid"> <TextBox Text="{Binding Name}" /> </Grid> <DataTemplate.Triggers> <DataTrigger Binding="{Binding isMismatch}" Value="True"> <Setter TargetName="templateGrid" Property="Background" Value="Red" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>更多推荐
WPF:一些组合框项目更改背景
发布评论