wpf datagrid binding datagridcell内容
-
29-09-2019 - |
题
希望这是一个非常简单的答案,我只是看不到我认为树木的谚语。
我有一个数据杂志样式,我想将单元格的内容绑定到图像的源属性,这是我目前正在使用的XAML:
<Style x:Key="DataGridImageCellStyle" TargetType="{x:Type toolkit:DataGridCell}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type toolkit:DataGridCell}">
<Border Background="Transparent"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
SnapsToDevicePixels="True">
<Image Source="{Binding RelativeSource={RelativeSource AncestorType=toolkit:DataGridCell}, Path=Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
请注意,目前我将图像源绑定到内容。.这是不起作用的,我也尝试了价值,但不起作用!
所以我的问题是,很好,简单..将单元的内容用于此图像的源属性,使用的绑定是什么?
提前致谢!
皮特
解决方案
如果该列是DataGridTextColumn,则您可以绑定到其内容的文本block的文本属性:
<Image Source="{Binding RelativeSource=
{RelativeSource AncestorType=DataGridCell}, Path=Content.Text}" />
不过,这确实是一个黑客。如果要在列中显示图像,则可能应该使用 DataGridTemplateColumn:
<DataGridTemplateColumn Header="...">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding SomeProperty}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
其中某些property是具有图像路径的行对象的属性。
不隶属于 StackOverflow