WPF 覆盖 DataGrid RowHeader 模板并仍然设法选择行
我已经覆盖了默认的行标题样式以使用我的自定义按钮:
<Style x:Key="RowHeaderStyle" TargetType="DataGridRowHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridRowHeader">
<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource RowHeaderButton}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
当然,问题是单击该按钮不再选择该行。我是否必须在 IsPressed 事件上调用自定义方法?我如何知道行索引?你会怎样做呢?
谢谢!
I have overriden the default row header style to use my custom button:
<Style x:Key="RowHeaderStyle" TargetType="DataGridRowHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridRowHeader">
<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource RowHeaderButton}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem of course is that clicking the button no longer selects the row. Will I have to call a custom method on the IsPressed event? How would I know the row index? How would you go about doing it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终只使用了样式,事实证明,如果不是太激烈的话,你可能可以做你想做的事。如果有人设法获取后面的代码来处理 DataGridHeaderBorder 上的行选择,请告诉我!
例子:
I've ended up using only styling which turns out you can probably do what you want if it isn't drastic. If anyone manages to get the code behind to handle row selection on DataGridHeaderBorder please let me know!
Example:
是的,您必须对自己选择的事件进行编码。
一种方法是使用 Blend 等工具获取默认模板的副本,然后修改其模板以包含您的更改。
Yes you will have to code your own selected event.
One way to do that is to get a copy of the default template using a tool like Blend and just modify their template to include your changes.