0
我想獲得以下PointerOver
VisualState的工作。理想情況下,當鼠標指針位於按鈕上時,我想用黑色邊框突出顯示該按鈕。爲什麼我的XAML按鈕PointerOver VisualState不工作?
我一直在嘗試各種方法使這項工作,請幫助。
注意:如果我設置了BorderHighlight,Border元素的BorderColor值,我就可以得到所需的邊框,但是當我將它作爲VisualState的一部分時不會。
<Style x:Key="SecondaryButton" TargetType="Button">
<Setter Property="Background" Value="LightSkyBlue"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Padding" Value="5"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="ButtonHighlight" BorderThickness="2" BorderBrush="Transparent">
<Grid>
<Rectangle x:Name="innerRectangle" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Stroke="Transparent"
StrokeThickness="20" Fill="{TemplateBinding Background}"
RadiusX="15" RadiusY="15" />
<ContentPresenter x:Name="Text" Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ColorAnimation From="Transparent" To="Black" Storyboard.TargetName="Text" Storyboard.TargetProperty="(Button.Foreground).(SolidColorBrush.Color)" BeginTime="0" Duration="1"></ColorAnimation>
<ColorAnimation From="Transparent" To="LightSkyBlue" Storyboard.TargetName="Text" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" BeginTime="0" Duration="1"></ColorAnimation>
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimation From="Transparent" To="Black" Storyboard.TargetName="ButtonHighlight" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Duration="0:0:1"></ColorAnimation>
</Storyboard>
.
.
.
我剪斷外來代碼保持問題短了點,不過這一切編譯,只是沒有得到想要的結果。我也可以使用2個矩形(比另一個小),但想使它與實際邊界一起工作。
而且這將是定位之間的區別:
<ColorAnimation From="Transparent" To="Black"
Storyboard.TargetName="ButtonHighlight"
Storyboard.TargetProperty="BorderBrush.(SolidColorBrush.Color)"
Duration="0:0:1"></ColorAnimation>
和
<ColorAnimation From="Transparent" To="Black"
Storyboard.TargetName="ButtonHighlight"
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
Duration="0:0:1"></ColorAnimation>
你從哪裏得到 「鼠標懸停」從? – Alwyn
嗯... http://snag.gy/4Skk4.jpg ...它可能與Windows 8不同...對不起,然後 –