【发布时间】:2016-01-26 20:05:06
【问题描述】:
我希望我能解释清楚....
我们将DataGrid 绑定到来自某个数据源的集合。
每列的属性在不同的集合中描述,因此我们在运行时创建列并根据属性集合中的值设置列的属性(例如只读)。
新要求是“必需”属性。对于所需的列,我想绑定一个转换器,该转换器根据该值设置 DataGridCell 的背景颜色。 (如果单元格为空,转换器最简单的情况是某种颜色,如果用户输入一个值,则为白色。我相信将来会出现更复杂的验证。)
我认为它可以用我现在正在修补的东西来完成:
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<TextBox Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}">
</TextBox>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
(仍然需要在某处添加转换器....)
还是我想做的事情必须在代码隐藏中完成?任何指针将不胜感激......
【问题讨论】:
标签: wpf data-binding wpfdatagrid