0

我想弄清楚如何使用 MouseOver 内部的 StackPanel 更改边框的 BorderColor。我尝试将 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>
4

1 回答 1

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

还是喜欢看另一边……

于 2012-11-04T00:50:42.250 回答