WPF Datagrid Binding DatagridCellコンテンツ
-
29-09-2019 - |
質問
これは本当に簡単な答えになることを願っています。私は、私が思う木のことわざの木材を見ていません。
セルの内容を画像のソースプロパティにバインドしたい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>
現時点では、画像ソースをコンテンツにバインドしています。機能しませんが、価値も試みましたが、うまくいきませんでした。
だから私の質問は、素敵で単純に..この画像のソースプロパティにセルのコンテンツを入手するために使用する正しいバインディングは何ですか?
前もって感謝します!
ピート
解決
列がdatagridTextColumnの場合、コンテンツであるTextBlockのテキストプロパティにバインドできる場合があります。
<Image Source="{Binding RelativeSource=
{RelativeSource AncestorType=DataGridCell}, Path=Content.Text}" />
しかし、それは本当にハックです。列に画像を表示したい場合は、おそらく使用する必要があります datagridtemplatecolumn:
<DataGridTemplateColumn Header="...">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding SomeProperty}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
一部のプロパティは、画像パスを持つ行オブジェクトのプロパティです。
所属していません StackOverflow