当前位置:网站首页>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 :
边栏推荐
- When FC connects to the database, do you have to use a custom domain name to access it outside?
- Interface automation test - solution of data dependency between interfaces
- Help tenants
- Battle Atlas: 12 scenarios detailing the requirements for container safety construction
- 带你掌握三层架构(建议收藏)
- 648. Word replacement: the classic application of dictionary tree
- UML 顺序图(时序图)
- 2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
- AutoCAD - how to input angle dimensions and CAD diameter symbols greater than 180 degrees?
- 为租客提供帮助
猜你喜欢
AI人才培育新思路,这场直播有你关心的
最长上升子序列模型 AcWing 1014. 登山
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Redis 核心数据结构 & Redis 6 新特性详
118. Yanghui triangle
Did login metamask
2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
得物客服热线的演进之路
.net core 关于redis的pipeline以及事务
AutoCAD - how to input angle dimensions and CAD diameter symbols greater than 180 degrees?
随机推荐
TPG x AIDU | AI leading talent recruitment plan in progress!
3D detection: fast visualization of 3D box and point cloud
Laravel5 call to undefined function OpenSSL cipher IV length() error php7 failed to open OpenSSL extension
2022-7-6 Leetcode 977.有序数组的平方
为租客提供帮助
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
Flask session forged hctf admin
Leetcode simple question sharing (20)
Xshell connection server changes key login to password login
【网络安全】sql注入语法汇总
手把手教会:XML建模
libSGM的horizontal_path_aggregation程序解读
Build a secure and trusted computing platform based on Kunpeng's native security
Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1
Lavarel之环境配置 .env
Cargo placement problem
Selenium库
requires php ~7.1 -&gt; your PHP version (7.0.18) does not satisfy that requirement
Reverse non return to zero code, Manchester code and differential Manchester code of common digital signal coding
Evolution of customer service hotline of dewu