WPF DataGrid 中选定行中的按钮样式
这似乎应该很简单,但我无法实现它......我有一个带有模板列的数据网格,其中包含一个按钮:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource LinkButton}" Content="{Binding Path=...}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
并且我的链接按钮样式如下所示:
<Style x:Key="LinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ControlTemplate.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
</ControlTemplate.Resources>
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Blue" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
选择该行时,我想要将链接按钮的前景色更改为白色或其他颜色。有没有一种简单的方法可以实现这一点?
This seems as if it should be simple, but I can't make it happen... I've got a datagrid with a template column that includes a button:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource LinkButton}" Content="{Binding Path=...}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
and my linkbutton style looks like this:
<Style x:Key="LinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ControlTemplate.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
</ControlTemplate.Resources>
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Blue" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
When the row is selected, I want to change the foreground color of the linkbutton to white or something. Is there an easy way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者类似的东西......
(顺便说一下,使用
DataGridHyperlinkColumn
怎么样,或者至少只是一个普通的Hyperlink
而不是按钮
?)Or something like that...
(By the way, what about using the
DataGridHyperlinkColumn
, or at the very least just a normalHyperlink
instead of aButton
?)