绑定到动画属性(WPF) [英] Bind to animated property (WPF)

查看:139
本文介绍了绑定到动画属性(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道,如果是使用的动画作为源绑定属性的方法吗?
至于我发现,是一个动画并没有真正的设置属性的值,因此不火已更改的事件,这是触发结合必要的。

Does anybody knows, if there is a way to use a property that is animated as source for a binding? As far as I found out, is that an animation doesn't "really" set the value on the property, and therefore doesn't fire the changed events, which is needed to trigger the binding.

TIA
马丁

tia Martin

推荐答案

我不知道你所说的是完全正确的。在下面的XAML,文本块将显示矩形的宽度。当你点击矩形,Width属性是从50到动画300沿着每一个增量,价值TextBlock的变化。难道我不理解你的问题?

I don't know if what you are saying is exactly true. In the XAML below, the TextBlock will display the Width of the Rectangle. When you click on the Rectangle, the Width property is animated from 50 to 300. Along every increment, the TextBlock changes in value. Am I not understanding your question?

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  <TextBlock Text="{Binding ElementName=Rect,Path=Width}" Grid.Row="0" />
  <Rectangle Grid.Row="1"
             Name="Rect"
             Height="30"
             Width="50"
             Fill="Blue"
             HorizontalAlignment="Left">
    <Rectangle.Triggers>
      <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation Storyboard.TargetProperty="Width"
                From="50"
                To="300"
                Duration="0:0:10"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Rectangle.Triggers>
  </Rectangle>
</Grid>

这篇关于绑定到动画属性(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆