2013-08-30 29 views
0

我想添加一個懸停效果到我創建的邊框,如下所示。WinRT - 邊框懸停改變不透明度

<Border x:Name="borderHeader" Background="#000000" Height="100" VerticalAlignment="top" Opacity="0.5" HorizontalAlignment="Left" Width="1366"> 

而且下面我的視覺狀態代碼。

<VisualStateManager.VisualStateGroups> 
<VisualState x:Name="PointerOver"> 

        <Storyboard> 
         <DoubleAnimation Duration="0" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="borderHeader"/> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
</VisualStateManager.VisualStateGroups> 

它永遠不能工作。 請告知我錯誤地做了哪部分。 謝謝

回答

0

視覺狀態可以適用於ControlTemplate內的那些控件。邊界是獨立控制。所以你需要依靠PointerEntered & PointerExited事件。

XAML

<Border x:Name="borderHeader" Background="Yellow" Height="100" VerticalAlignment="top" Opacity="0.5" HorizontalAlignment="Left" Width="1366" 
       PointerEntered="borderHeader_PointerEntered_1" PointerExited="borderHeader_PointerExited_1"/> 

C#

private void borderHeader_PointerEntered_1(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) 
{ 
    borderHeader.Opacity = 1; 
} 

private void borderHeader_PointerExited_1(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) 
{ 
    borderHeader.Opacity = 0.5; 
}