gpt4 book ai didi

C# WPF 鼠标悬停按钮 - 无内容

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:02 25 4
gpt4 key购买 nike

我刚刚编辑了这个按钮。因为我想要鼠标悬停效果。不幸的是 Button 的内容没有显示。如果我将鼠标悬停在上面,我想更改字体颜色。

<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="{x:Null}" Canvas.Top="42">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>

最佳答案

Unfortunately the content of Button is not displayed.

不要将 Foreground 属性设置为 {x:Null}:

And I would like to change the font color, if I go with the mouse over it.

IsMouseOver 触发器中添加一个设置 Foreground 属性的 setter:

<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" 
HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Canvas.Top="42">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>

关于C# WPF 鼠标悬停按钮 - 无内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42388719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com