我想弄清楚如何用MouseOver改变Border的BorderColor里面的StackPanel。我试过将TargetName设置为StackPanel的VSM内部边框的名称。我知道我离开了,但我宁愿尝试一下......
<Border x:Name="LinksBorder" >
<StackPanel x:Name="LinksStackPanel" Margin="10" Orientation="Horizontal" FlowDirection="RightToLeft" HorizontalAlignment="Center" Width="311">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation
Duration="0" Storyboard.TargetName="LinksBorder" Storyboard.TargetProperty="(BorderBrush).(SolidBrush)" To="#FF0000" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
答案 0 :(得分:0)
我的解决方法:
Private Sub LinksStackPanel_MouseEnter(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles LinksStackPanel.MouseEnter
LinksBorder.BorderBrush = New Media.SolidColorBrush(Colors.Red)
End Sub
Private Sub LinksStackPanel_MouseLeave(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles LinksStackPanel.MouseLeave
LinksBorder.BorderBrush = ColorFromHex("#FF00FF2A")
End Sub
Private Function ColorFromHex(hex As String) As Brush
hex = hex.Replace("#", String.Empty)
Dim a = (Convert.ToUInt32(hex.Substring(0, 2), 16))
Dim r = (Convert.ToUInt32(hex.Substring(2, 2), 16))
Dim g = (Convert.ToUInt32(hex.Substring(4, 2), 16))
Dim b = (Convert.ToUInt32(hex.Substring(6, 2), 16))
Return New SolidColorBrush(Color.FromArgb(CByte(a), CByte(r), CByte(g), CByte(b)))
End Function
还是喜欢看另一种方式......