1
我想修改按鈕的文本顏色,當鼠標懸停,從黑到另一種顏色,我用這個風格:改變文字顏色,當懸停在一個按鈕,在UWP
<Style x:Key="ButtonmenuStyle"
TargetType="Button">
<Setter Property="Foreground" Value="#393185"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimation Duration="0" To="#393185" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Content1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Duration="0" To="#393185" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Content1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid>
<ContentPresenter x:Name="Content1"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但與此代碼的問題是,我得到的結果,在懸停(懸停顏色發生了變化),但按鈕的文字是不是在左中央顯示,這是結果:
這是我的代碼,將按鈕應用於樣式:
<Button BorderThickness="0" Background="Transparent" Content="Nouveau Local" FontSize="18" Foreground="#393185" x:Name="res9" HorizontalAlignment="Left" Height="50" Grid.Column="1" Style="{Binding Source={StaticResource ButtonmenuStyle}}"/>
請我怎麼能改正我的代碼,在左心 感謝您的幫助
任何幫助請:( – user3821206