【发布时间】:2012-12-14 05:08:26
【问题描述】:
我有以下 Windows Phone 代码,用于将 Rectangle 的颜色从黑色更改为红色。
<Grid x:Name="LayoutRoot">
<phone:Pivot x:Name="MyPivot" >
<phone:PivotItem x:Name="MyPivotItem">
<Canvas x:Name="MyCanvas">
<Canvas.Resources>
<Storyboard x:Name="MyStoryboard">
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
AutoReverse="True">
<EasingColorKeyFrame KeyTime="00:00:0" Value="Black" />
<EasingColorKeyFrame KeyTime="00:00:0.5" Value="Red" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Canvas.Resources>
</Canvas>
</phone:PivotItem>
</phone:Pivot>
</Grid>
我想做的是让它更加动态,以便我可以从代码隐藏页面更改EasingColorKeyFrames 中使用的颜色。是否可以将我的EasingColorKeyFrames 的Value 绑定到我的代码隐藏页面中的属性?
【问题讨论】:
-
Aren
t you trying to bind to properties of Grid named 'LayoutRoot' that doesnt 有你的颜色属性吗?在文章中作者绑定到 UserControl 本身,而不是 Grid。 -
啊,你是对的。我想我误解了第一次但再次阅读它似乎更清楚,我会从问题中删除它。你知道我可以从我的代码隐藏页面绑定属性的方法吗?
-
@AntSlay 对这个问题的回答与我之前尝试的类似,但使用的是页面名称而不是 LayoutRoot:stackoverflow.com/questions/5130937/…。今晚我会试一试!
标签: silverlight binding storyboard windows-phone windows-phone-8