当前位置:网站首页>通过 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 效果图:
边栏推荐
- THINKPHP框架的优秀开源系统推荐
- [network security] SQL injection syntax summary
- 2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
- 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)
- TPG x AIDU | AI leading talent recruitment plan in progress!
- Excuse me, as shown in the figure, the python cloud function prompt uses the pymysql module. What's the matter?
- [high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
- 請問,在使用flink sql sink數據到kafka的時候出現執行成功,但是kafka裏面沒有數
- Attribute keywords aliases, calculated, cardinality, ClientName
- SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
猜你喜欢

得物客服热线的演进之路

Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1

Build a secure and trusted computing platform based on Kunpeng's native security

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

Flask session forged hctf admin

高等数学---第八章多元函数微分学1

Vmware共享主机的有线网络IP地址
![Supply chain supply and demand estimation - [time series]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
Supply chain supply and demand estimation - [time series]
![SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1](/img/10/6de1ee8467b18ae03894a8d5ba95ff.png)
SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1

Battle Atlas: 12 scenarios detailing the requirements for container safety construction
随机推荐
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
Navicat run SQL file import data incomplete or import failed
postgresql array类型,每一项拼接
AutoCAD - how to input angle dimensions and CAD diameter symbols greater than 180 degrees?
toRaw和markRaw
Evolution of customer service hotline of dewu
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
参数关键字Final,Flags,Internal,映射关键字Internal
得物客服热线的演进之路
When FC connects to the database, do you have to use a custom domain name to access it outside?
"New red flag Cup" desktop application creativity competition 2022
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
请问,如图,pyhon云函数提示使用了 pymysql模块,这个是怎么回事?
Environment configuration of lavarel env
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
Help tenants
. Net core about redis pipeline and transactions
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
docker部署oracle