問題描述
XNA/XAML 鼠標懸停時動畫邊框顏色 (XNA/XAML Animate border color on mouseover)
I am making an image gallery in XNA and XAML. I need to have images with borders and on mouseover I want to change the border color. I tried different things which didn't work. When the IMAGE is mouseOvered the animation to change the border color should be triggered. Here is my code:
<Border Name="myBorder"
BorderThickness="5"
BorderBrush="White"
Width="100"
Height="100"
Padding="0"
Margin="15"
CornerRadius="10">
<Border.Style>
<Style>
<Style.Triggers>
<Trigger Property="Image.IsMouseOver" Value="True">
<Setter Property="Border.BorderBrush" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Image Name="myImage1"
HorizontalAlignment="Center"
Stretch="Fill" />
</Border>
I also used EventTrigger and Storyboard with mo success. Is there someone who knows how to do this?
參考解法
方法 1:
Ok, I solved the problem thanks to this post
I should have removed the BorderBrush from the border definition. Now this works:
<Border Name="myBorder"
BorderThickness="5"
Width="100"
Height="100"
Padding="0"
Margin="15"
CornerRadius="10">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<Trigger Property="Image.IsMouseOver" Value="True">
<Setter Property="Border.BorderBrush" Value="Yellow"/>
</Trigger>
<Trigger Property="Image.IsMouseOver" Value="False">
<Setter Property="Border.BorderBrush" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Image Name="myImage1" HorizontalAlignment="Center" Stretch="Fill" />
</Border>
(by mahsa.teimourikia、mahsa.teimourikia)