如何在WPF中将颜色设置为datagrid单元格 [英] How to set color to datagrid cell in WPF

查看:142
本文介绍了如何在WPF中将颜色设置为datagrid单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望根据sql database的值将颜色设置为数据网格中的单元格。我在代码下面键入并执行它将运行但它不会在单元格中显示任何颜色。我没有找到解决方案问题。请帮助我



我尝试过的事情:



 <   DataGrid    名称  =  dg >  
< datagrid.columns >
< DataGridTextColumn Binding = {Binding Name} >
< DataGridTextColumn Binding = {Binding Status} >
< datagridtextcolumn.element style >
< Style.Triggers >
< 触发器 属性 = 文本 = 1 >
< span class =code-keyword><
Setter Property = 背景 = 蓝色 / >
< / trigger >
< ; 触发r 属性 = 文字 = 2 >
< Setter 属性 = 背景 = 绿色 / >
< / trigger >
< / style 。触发器 >

解决方案

检查Caroline的过去答案:如何更改数据网格的单个单元格颜色在wpf? [ ^ ]

I want set the color to cell in the datagrid from based on the value of sql database.I typed below code and execute it will run but it dose not show any color in the cell.I did not find the solution to this problem.Help me please

What I have tried:

<DataGrid Name="dg">
            <datagrid.columns>
                <DataGridTextColumn Binding="{Binding Name}">
                <DataGridTextColumn Binding="{Binding Status}">
                    <datagridtextcolumn.elementstyle>
                       <Style.Triggers>
                         <Trigger Property="Text" Value="1">
                             <Setter Property="Background" Value="Blue"/>
                         </trigger>
                         <Trigger Property="Text" Value="2">
                             <Setter Property="Background" Value="Green"/>
                         </trigger>
                        </style.Triggers>

解决方案

Check Caroline's past answer: How to change single cell color of datagrid in wpf?[^]


这篇关于如何在WPF中将颜色设置为datagrid单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆