WPF:一些组合框项目更改背景

编程入门 行业动态 更新时间:2024-10-28 00:18:06
本文介绍了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:一些组合框项目更改背景

本文发布于:2023-11-28 22:33:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   背景   项目   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!