![](/img/trans.png)
[英]Change the button default highlighted colour to transparent on mouseover XAML wpf?
[英]WPF XAML - Override a button's MouseOver look
我嘗試了在本網站或其他網站上找到的所有其他解決方案,但它不起作用。 這是按鈕:
<Button Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="10,10,5,10" BorderThickness="3">
<Button.Background>
<SolidColorBrush Opacity="0.0" Color="#b3b3b3"/>
</Button.Background>
<Button.BorderBrush>
<SolidColorBrush Opacity="0.3" Color="Gray"/>
</Button.BorderBrush>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="5*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</Button>
我嘗試了什么:
在Windows.Resources
添加樣式:
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
並在按鈕內添加此項。 我得到的兩個解決方案要么是沒有,舊的突出顯示的外觀,或者我無法兩次更改Content
的錯誤。 由於我沒有想法,有人可以告訴我如何更改按鈕突出顯示的外觀嗎?
編輯:
從我在答案中提到的帖子中按字符復制字符:
<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="50" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="50,0,0,0">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Green"/>
<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="DarkGoldenrod"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
現在它有效。 它沒有的原因是我自己的按鈕 - 在這個問題 - 有一些自己的屬性,如那些brushes
和grid
。
更新:所有解決方案都可以使用,他們沒有給我的原因是我的按鈕在它們內部定義了自己的風格。 一旦我評論了我的舊按鈕並添加了這樣的裸按鈕:
編輯:
在這里我說define their own style
。 這是一種錯誤的方式來稱呼它,我的意思是畫筆和網格。
這個線程做了伎倆。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.