WPF DataGrid中对DataGridTextColumn中Style的属性设置Binding

林夕合鸟 林夕合鸟 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有点绕,直接上代码:

<DataGrid x:Name="dgMain" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="+0" Binding="{Binding Value0}" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding Value0}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>


我想在C#代码中实现以上内容,如何实现?谢谢了!在线急等!
关键在加红部分代码,其他我已经实现:
代码如下:
SingleData d = new SingleData();
d.Value0 = 5;
d.Value1 = 10;

list.Add(d);

DataGridTextColumn column = new DataGridTextColumn();
column.Header = "+0";
Binding bind = new Binding();

bind.Path = new PropertyPath("Value0");

column.Binding = bind;


dgMain.Columns.Add(column);

dgMain.ItemsSource = list;
...全文
评论 1
收藏 已收藏
分享
返回顶部
林夕合鸟
WPF/Silverlight 8,757 成员 12,031 内容