2012-11-03 38 views
0

我想弄清楚如何用MouseOver來改變邊框的邊框顏色。我嘗試了將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

我的解決方法:

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 

仍希望看到太多的其他方式...