0
我是WinRT/XAML開發新手。經過幾個小時的網絡研究和許多嘗試和錯誤嘗試後,我仍然無法理解如何使用VisualStateManager根據用戶對對象的輸入更改橢圓的填充顏色。以下代碼不起作用。下面是代碼今天因爲它位於:WinRT/XAML在鼠標上改變橢圓的填充顏色
<Ellipse Stroke="White" StrokeThickness="5" Width="90" Height="90">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation To="Red" Storyboard.TargetName="Ellipse" Storyboard.TargetProperty="Fill.Color"/>
</Storyboard>
</VisualState>
<VisualStateGroup.Transitions>
<VisualTransition To="Normal" GeneratedDuration="00:00:01"/>
<VisualTransition To="MouseOver" GeneratedDuration="00:00:01"/>
</VisualStateGroup.Transitions>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Ellipse>
UPDATE:
謝謝尼古拉斯W.在正確的方向輕推。我錯過了模板以及正確的目標屬性。下面的代碼如預期運行:
<Button>
<Button.Template>
<ControlTemplate>
<Grid>
<Ellipse x:Name="myEllipse" Stroke="White" StrokeThickness="5" Width="70" Height="70" Fill="Transparent"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Storyboard.TargetName="myEllipse" To="#FF0061D4" Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" Duration="0:0:0"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
我的WinRT技能是有限的;但是TargetName會拒絕一個不存在的元素。 Ellipse是對象名稱,而不是它的「名稱」,嘗試刪除TargetName,然後動畫將定位該元素本身。如果這不起作用,請給你Ellipse一個名字和參考。 – dowhilefor 2013-03-01 15:05:56