WPF DataGrid 绑定 DataGridCell 内容
希望这将是一个非常简单的答案,我认为我只是没有看到众所周知的树木。
我有一个 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>
请注意,目前我将图像源绑定到内容..这不起作用,我也尝试过价值,但不起作用!
所以我的问题是,很好,很简单......用于将单元格的内容放入该图像的源属性中的正确绑定是什么?
提前致谢!
皮特
This is hopefully going to be a really simple answer, I'm just not seeing the proverbial wood for the trees I think.
I've got a DataGridCell style in which I want to bind the content of the cell to the source property of an image, here's the XAML I'm using at the moment:
<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>
Note that at the moment i'm binding the Image Source to Content.. which doesnt work, i've also tried Value, which didn't work!
So my question is, nice and simply.. what is the correct binding to use to get the cell's content into the source property of this image?
Thanks in advance!
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果该列是 DataGridTextColumn,那么您可能能够绑定到作为其内容的 TextBlock 的 Text 属性:
不过,这确实是一个 hack。如果要在列中显示图像,您可能应该使用 DataGridTemplateColumn:
其中 SomeProperty 是具有图像路径的行对象的属性。
If the column is a DataGridTextColumn then you might be able to bind to the Text property of the TextBlock that is its content:
That's really a hack, though. If you want to display an image in a column, you should probably use a DataGridTemplateColumn:
Where SomeProperty is the property of your row object that has the image path.