当我在XAML/VB中将鼠标悬停在按钮上时,如何禁用它变蓝



我在Visual Studio Blend中创建了一个登录表单。然而,当你把鼠标悬停在我使用的按钮上时,它会变蓝。有没有办法阻止它,因为它真的让我很困扰。在搜索了它之后,出现了一些解决方案,但我并不真正理解它们。因此,我正在寻找一个基本而简单的解决方案。我的XAML代码(如果有帮助的话(:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NEA"
mc:Ignorable="d"
Title="Log In" Height="297" Width="345">
<Grid Background="#FF403939" Height="267" VerticalAlignment="Top" HorizontalAlignment="Left" Width="337">
<TextBox x:Name="txtUserName" HorizontalAlignment="Left" Height="26.774" Margin="8.778,48.444,0,0" TextWrapping="Wrap" Text="Username" VerticalAlignment="Top" Width="317.529" BorderBrush="White" Background="#FF4D4B4B" Foreground="White"/>
<TextBox x:Name="txtPassword" HorizontalAlignment="Left" Height="26.774" Margin="8.778,88.604,0,0" TextWrapping="Wrap" Text="Password" VerticalAlignment="Top" Width="317.529" BorderBrush="White" Background="#FF4D4B4B" Foreground="White"/>
<CheckBox x:Name="chkRememberMe" Content="Remember Me" HorizontalAlignment="Left" Margin="19.778,137.399,0,0" VerticalAlignment="Top" Foreground="White" Background="#FF726969"/>
<Border x:Name="bor1" BorderBrush="White" BorderThickness="1" Height="41" Margin="8.778,174.864,0,0"  CornerRadius="15" Background="#FF499E3C" HorizontalAlignment="Left" Width="317.529" VerticalAlignment="Top">
<Button x:Name="btnLogIn" Content="Log In" BorderBrush="#00707070" ClipToBounds="True" Background="#01F4F7FC" Foreground="White" HorizontalAlignment="Left" Width="297.529" Height="41" VerticalAlignment="Top" Margin="9,-1,0,-1" >
</Button> 
</Border>
<Button x:Name="btnForgot" Content="Forgotten Password" HorizontalAlignment="Left" Height="24.601" Margin="186,132.079,0,0" VerticalAlignment="Top" Width="124" Background="#00DDDDDD" Foreground="#FF00C5FF" BorderBrush="#00707070"/>
<Label Content="Sign In" HorizontalAlignment="Left" Height="35.444" Margin="8.778,8,0,0" VerticalAlignment="Top" Width="77.222" Foreground="White" FontSize="18"/>
<Label Content="Don't have an account?" HorizontalAlignment="Left" Height="31" Margin="63.35,233,0,0" VerticalAlignment="Top" Width="147.65" Foreground="#FFA09D9D"/>
<Button x:Name="btnSignUp" Content="Sign Up" HorizontalAlignment="Left" Height="22" Margin="186,234.98,0,0" VerticalAlignment="Top" Width="75.572" Background="#00DDDDDD" BorderBrush="#00707070" Foreground="#FFC3C0C0" FontWeight="Bold"/>
</Grid>
</Window>

基本答案是编辑按钮的模板,并修改使用IsMouseOver属性的触发器中设置的背景色。我相信你会发现这个触发器将背景设置为"#FFBEE6FD"",这是一种浅蓝色。

要编辑按钮的模板,请在"文档大纲"窗格中右键单击按钮,然后选择编辑模板>编辑副本。这将插入按钮的默认ControlTemplate。底部是与IsMouseOver属性相关联的触发器。下面是背景的设置器,如果您喜欢,可以在其中更改颜色,或者删除设置器,背景将不再更改。

如果您根据上面的内容右键单击以编辑模板,VS将自动为该按钮插入一行Template= "your template name"。您可以将同一行用于其他按钮以获得相同的结果。或者,您可以创建一个按钮样式,并提供一个用于分配此模板的setter。然后对每个想要相同结果的按钮使用此样式。

最新更新