希望这将是一个非常简单的答案,我只是没有看到俗话所说的树木换来的树木。
我有一个DataGridCell样式,希望将单元格的内容绑定到图像的源属性,下面是我目前正在使用的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>请注意,目前我正在将Image Source绑定到Content..这不起作用,我也尝试了Value,但没有起作用!
所以我的问题是,很好,很简单..要将单元格的内容放入此图像的source属性,正确的绑定是什么?
提前感谢!
皮特
发布于 2010-08-17 20:41:34
如果该列是一个文本,那么您可以绑定到TextBlock的DataGridTextColumn属性,即它的内容:
<Image Source="{Binding RelativeSource=
{RelativeSource AncestorType=DataGridCell}, Path=Content.Text}" />不过,这真的是一种黑客手段。如果要在列中显示图像,则可能应该使用DataGridTemplateColumn:
<DataGridTemplateColumn Header="...">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding SomeProperty}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>其中SomeProperty是具有图像路径的行对象的属性。
https://stackoverflow.com/questions/3502173
复制相似问题