当前位置:网站首页>Assign a dynamic value to the background color of DataGrid through ivalueconverter
Assign a dynamic value to the background color of DataGrid through ivalueconverter
2022-07-07 14:12:00 【Peacock Flying Southeast - Shenzhen】
1 Create a class
public class A
{
private string _result;
public string Result
{
get { return _result; }
set { _Title = result; }
}
}
2 Create a ColorConverter class Inherited from IValueConverter class
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 stay xaml Written in a file :
<Window.Resources>
<local:ColorConverter x:Key="MyColorConvert"/>
</Window.Resources>
4 stay <DataGrid.Columns> It's written inside :
<DataGridTemplateColumn Width="150" >
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Result" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<!-- Column content -->
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Result}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="{Binding Result,Converter={StaticResource MyColorConvert}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
5 Write... In the main function :
private List<A> _con;
public List<A> Con
{
get { return _con; }
set { _con = value; }
}
6 stay mainwindow Write :
if(Con == null)
{
Con = new List<A>();
Con.Add(new A()
{
Result = "Success";
});
Con.Add(new A()
{
Result = "Fail";
});
dataGrid.ItemsSource = Con;
}
7 design sketch :
边栏推荐
- PHP中用下划线开头的变量含义
- Build a secure and trusted computing platform based on Kunpeng's native security
- Reverse non return to zero code, Manchester code and differential Manchester code of common digital signal coding
- Learning breakout 2 - about effective learning methods
- 内存溢出和内存泄漏的区别
- Transferring files between VMware and host
- Excuse me, I have three partitions in Kafka, and the flinksql task has written the join operation. How can I give the join operation alone
- Help tenants
- CSMA/CD 载波监听多点接入/碰撞检测协议
- js 获取当前时间 年月日,uniapp定位 小程序打开地图选择地点
猜你喜欢
XML文件的解析操作
高等数学---第八章多元函数微分学1
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)
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
566. 重塑矩阵
Redis can only cache? Too out!
为租客提供帮助
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
Leetcode simple question sharing (20)
. Net core about redis pipeline and transactions
随机推荐
gvim【三】【_vimrc配置】
Transferring files between VMware and host
mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
Evolution of customer service hotline of dewu
3D detection: fast visualization of 3D box and point cloud
Is the spare money in your hand better to fry stocks or buy financial products?
交换机和路由器的异同
Parameter keywords final, flags, internal, mapping keywords internal
Learning breakout 2 - about effective learning methods
Use day JS let time (displayed as minutes, hours, days, months, and so on)
What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?
請問,在使用flink sql sink數據到kafka的時候出現執行成功,但是kafka裏面沒有數
LeetCode简单题分享(20)
Supply chain supply and demand estimation - [time series]
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
Hands on Teaching: XML modeling
AI人才培育新思路,这场直播有你关心的
常用数字信号编码之反向不归零码码、曼彻斯特编码、差分曼彻斯特编码
How does MySQL control the number of replace?