5

これは本当に簡単な答えになることを願っています、私は私が思う木のためのことわざの木を見ていません。

セルのコンテンツを画像のソースプロパティにバインドする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>

現時点では、画像ソースをコンテンツにバインドしていますが、これは機能しませんが、Valueも試しましたが、機能しませんでした。

だから私の質問は、素晴らしくて単純です..セルのコンテンツをこの画像のソースプロパティに取得するために使用する正しいバインディングは何ですか?

前もって感謝します!

ピート

4

1 に答える 1

6

列がDataGridTextColumnの場合、そのコンテンツであるTextBlockのTextプロパティにバインドできる可能性があります。

<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は、画像パスを持つ行オブジェクトのプロパティです。

于 2010-08-17T12:41:34.193 に答える