C# WPF DataGrid绑定DataGridCell内容

C# WPF DataGrid绑定DataGridCell内容,c#,wpf,data-binding,datagrid,datagridcell,C#,Wpf,Data Binding,Datagrid,Datagridcell,希望这将是一个非常简单的答案,我只是没有看到我所认为的“树为木”的谚语 我有一个DataGridCell样式,我想将单元格的内容绑定到图像的源属性,下面是我目前使用的XAML: <Style x:Key="DataGridImageCellStyle" TargetType="{x:Type toolkit:DataGridCell}"> <Setter Property="Background" Value="Transparent" /> <Se

希望这将是一个非常简单的答案,我只是没有看到我所认为的“树为木”的谚语

我有一个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>

请注意,目前我正在将图像源绑定到内容。。这不起作用,我也尝试了价值,但没有起作用

所以我的问题是,好的,简单的。。要使用什么样的正确绑定将单元格内容放入此图像的源属性中

提前谢谢


Pete

如果列是DataGridTextColumn,则可以绑定到TextBlock的文本属性,该属性是其内容:

<Image Source="{Binding RelativeSource=
     {RelativeSource AncestorType=DataGridCell}, Path=Content.Text}" />

不过,这真是一个骇客。如果要在列中显示图像,可能应使用:



其中SomeProperty是具有图像路径的行对象的属性

感谢您的回复,我最终选择了黑客,以避免陷入更多的时间!出于好奇。。。如果我使用DataGridTemplateColumn,那么当单元格绑定到DataTableRow中的单元格时,您希望绑定路径是什么?再次感谢@GreatSeaSpider:我认为当您绑定到DataTable时,您使用DataColumn.ColumnName值作为绑定路径。
<DataGridTemplateColumn Header="...">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Source="{Binding SomeProperty}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>