当前位置:网站首页>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 :
边栏推荐
- Build a secure and trusted computing platform based on Kunpeng's native security
- docker部署oracle
- 648. Word replacement: the classic application of dictionary tree
- 2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
- 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
- Wired network IP address of VMware shared host
- Selenium库
- . Net core about redis pipeline and transactions
- PHP中用下划线开头的变量含义
- 【立体匹配论文阅读】【三】INTS
猜你喜欢
Evolution of customer service hotline of dewu
docker部署oracle
566. Reshaping the matrix
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
SAKT方法部分介绍
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
Redis 核心数据结构 & Redis 6 新特性详
libSGM的horizontal_path_aggregation程序解读
手把手教会:XML建模
Help tenants
随机推荐
How does MySQL control the number of replace?
TPG x AIDU | AI leading talent recruitment plan in progress!
Cargo placement problem
常用數字信號編碼之反向不歸零碼碼、曼徹斯特編碼、差分曼徹斯特編碼
Huawei image address
请问指南针股票软件可靠吗?交易股票安全吗?
数据流图,数据字典
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(二)
118. Yanghui triangle
PHP中用下划线开头的变量含义
Laravel5 call to undefined function OpenSSL cipher IV length() error php7 failed to open OpenSSL extension
请问,我kafka 3个分区,flinksql 任务中 写了 join操作,,我怎么单独给join
"New red flag Cup" desktop application creativity competition 2022
Excellent open source system recommendation of ThinkPHP framework
Is the compass stock software reliable? Is it safe to trade stocks?
3D Detection: 3D Box和点云 快速可视化
Parsing of XML files
FC连接数据库,一定要使用自定义域名才能在外面访问吗?