当前位置:网站首页>通过 iValueConverter 给datagrid 的背景颜色 动态赋值
通过 iValueConverter 给datagrid 的背景颜色 动态赋值
2022-07-07 12:10:00 【孔雀东南飞-深圳】
1 创建一个类
public class A
{
private string _result;
public string Result
{
get { return _result; }
set { _Title = result; }
}
}2 创建一个 ColorConverter 类 继承自 IValueConverter 类
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//throw new NotImplementedException();
if(value as string == "Success")
{
return "Green";
}
else
{
return "Red";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}3 在 xaml 文件中写:
<Window.Resources>
<local:ColorConverter x:Key="MyColorConvert"/>
</Window.Resources>4 在 <DataGrid.Columns> 里写:
<DataGridTemplateColumn Width="150" >
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Result" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<!--列内容-->
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Result}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="{Binding Result,Converter={StaticResource MyColorConvert}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>5 在主函数中写:
private List<A> _con;
public List<A> Con
{
get { return _con; }
set { _con = value; }
}6 在 mainwindow 写:
if(Con == null)
{
Con = new List<A>();
Con.Add(new A()
{
Result = "Success";
});
Con.Add(new A()
{
Result = "Fail";
});
dataGrid.ItemsSource = Con;
}7 效果图:
边栏推荐
- Thread pool reject policy best practices
- 2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
- Is the spare money in your hand better to fry stocks or buy financial products?
- Redis只能做缓存?太out了!
- Cesium 已知一点经纬度和距离求另一个点的经纬度
- Is the compass stock software reliable? Is it safe to trade stocks?
- requires php ~7.1 -&gt; your PHP version (7.0.18) does not satisfy that requirement
- Leetcode simple question sharing (20)
- Supply chain supply and demand estimation - [time series]
- Navicat run SQL file import data incomplete or import failed
猜你喜欢

2022-7-7 Leetcode 844. Compare strings with backspace

2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array

"New red flag Cup" desktop application creativity competition 2022

Xshell connection server changes key login to password login

为租客提供帮助

Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou

Take you to master the three-tier architecture (recommended Collection)

交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)

MySQL error 28 and solution

2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
随机推荐
Evolution of customer service hotline of dewu
云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
Excusez - moi, l'exécution a été réussie lors de l'utilisation des données de puits SQL Flink à Kafka, mais il n'y a pas de nombre dans Kafka
2022-7-6 beginner redis (I) download, install and run redis under Linux
高等数学---第八章多元函数微分学1
AutoCAD - how to input angle dimensions and CAD diameter symbols greater than 180 degrees?
【面试高频题】难度 2.5/5,简单结合 DFS 的 Trie 模板级运用题
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Data refresh of recyclerview
"New red flag Cup" desktop application creativity competition 2022
Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1
Regular expression integer positive integer some basic expressions
请问,在使用flink sql sink数据到kafka的时候出现执行成功,但是kafka里面没有数
Realization of search box effect [daily question]
648. Word replacement: the classic application of dictionary tree
为租客提供帮助
手把手教会:XML建模
Redis只能做缓存?太out了!
请问,我kafka 3个分区,flinksql 任务中 写了 join操作,,我怎么单独给join