將此樣式應用于我自己的用戶控制元件,該控制元件繼承自 Button:
<Style
x:Key="FunctionButtonStyle"
TargetType="uc:FunctionButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="uc:FunctionButton">
<RelativePanel
x:Name="MyPanel"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}">
<SymbolIcon
Margin="5"
RelativePanel.AlignTopWithPanel="True"
Symbol="{TemplateBinding Symbol}">
<SymbolIcon.RenderTransform>
<ScaleTransform CenterX="0" CenterY="0" ScaleX="0.5" ScaleY="0.5" />
</SymbolIcon.RenderTransform>
</SymbolIcon>
<TextBlock
Margin="5"
FontSize="10"
RelativePanel.AlignBottomWithPanel="True"
Text="{TemplateBinding Content}" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="MyPanel" />
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="MyPanel.Background" Value="Black" />
<Setter Target="ContentPresenter.BorderBrush" Value="#323232" />
<Setter Target="ContentPresenter.Foreground" Value="#00B7EB" />
</VisualState.Setters>
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="MyPanel" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</RelativePanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Width" Value="75" />
<Setter Property="Height" Value="45" />
</Style>
將此樣式應用于我的用戶控制元件,但滑鼠懸停顏色未生效,或者滑鼠懸停事件從未發生。
uj5u.com熱心網友回復:
您需要致電:
VisualStateManager.GoToState(this, "PointerOver", useTransitions: true);
在PointerEntered處理程式上,并且
VisualStateManager.GoToState(this, "Normal", useTransitions: true);
在PointerExited處理程式上。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/522055.html
