Wpf 如何将宽度图像与datagridcell宽度匹配
这是我的问题:选择行的唯一方法是单击图像(绿色圆圈) 我想做的是:当我点击Wpf 如何将宽度图像与datagridcell宽度匹配,wpf,datagrid,datagridcell,Wpf,Datagrid,Datagridcell,这是我的问题:选择行的唯一方法是单击图像(绿色圆圈) 我想做的是:当我点击DataGridCell时,不仅仅是图像,整个行都被选中 我有DataGridTemplateColumn在DataGrid中显示图像 我将SelectionMode=“Single”SelectionUnit=“FullRow”设置为数据网格属性 但是如果我没有准确地单击图像,该行将不会被选中 SCREESHOTS 我做了一些截图来更清楚地解释: 图像的大小: DataGridCell的大小 因此,在我看来,问题
DataGridCell
时,不仅仅是图像,整个行都被选中
我有DataGridTemplateColumn
在DataGrid
中显示图像
我将SelectionMode=“Single”SelectionUnit=“FullRow”
设置为数据网格属性
但是如果我没有准确地单击图像,该行将不会被选中
SCREESHOTS 我做了一些截图来更清楚地解释: 图像的大小: DataGridCell的大小
因此,在我看来,问题可能来自两个方面:
- 大小图像不适合整个
,这就是原因,但我如何才能适合它单元格
选择被禁用,我可以启用它单元格
编辑1
<DataGridTemplateColumn Header="{Binding, Source={StaticResource proxy}}" HeaderStyle="{StaticResource }" ClipboardContentBinding="{Binding}">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<Grid>
<Image Source="{Binding }" Style="{DynamicResource }" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
对于那些想知道它是关于什么的人:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid>
<ContentPresenter Padding="5,1" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
这使得图像错误。。。我不知道为什么,但是点击图片会失去效果。。。不知道更多,我用了另一种方法将
填充
添加到行中。使用边距
而不是填充
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Margin="5,1">
<ContentPresenter/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
在DataGridTemplate列中的图像周围放置一个网格
,并将背景设置为透明
。已经这样做了。我添加了一个例子来说明我是如何创建了DataGridTemplateColumn
我不知道你的问题出在哪里:奇怪,但这意味着问题来自我添加的东西。。。谢谢你@Dominic,我会在找到答案后发布答案!您可以发布您的DataGridStyle和HeaderStyle,以便我们可以查找。我看不到任何更改。。它优于填充
,但无论有无边距
,都是一样的:/