当前位置:网站首页>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 :
边栏推荐
- PERT图(工程网络图)
- IP address home location query full version
- 3D Detection: 3D Box和点云 快速可视化
- 【立体匹配论文阅读】【三】INTS
- 请问,redis没有消费消息,都在redis里堆着是怎么回事?用的是cerely 。
- gvim【三】【_vimrc配置】
- Dry goods | summarize the linkage use of those vulnerability tools
- How can the PC page call QQ for online chat?
- Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
- 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)
猜你喜欢
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
Parsing of XML files
js 获取当前时间 年月日,uniapp定位 小程序打开地图选择地点
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
UML 顺序图(时序图)
VSCode 配置使用 PyLint 语法检查器
手把手教会:XML建模
2022-7-6 beginner redis (I) download, install and run redis under Linux
566. 重塑矩阵
随机推荐
requires php ~7.1 -&gt; your PHP version (7.0.18) does not satisfy that requirement
mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
一个简单LEGv8处理器的Verilog实现【四】【单周期实现基础知识及模块设计讲解】
Leetcode simple question sharing (20)
Wired network IP address of VMware shared host
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
c#通过frame 和 page 切换页面
Did login metamask
When FC connects to the database, do you have to use a custom domain name to access it outside?
The difference between memory overflow and memory leak
Xshell connection server changes key login to password login
Flink | multi stream conversion
Laravel form builder uses
Clickhouse (03) how to install and deploy Clickhouse
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
Leecode3. Longest substring without repeated characters
为租客提供帮助
最长上升子序列模型 AcWing 1014. 登山
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?