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

查看:45
本文介绍了绑定到动画属性 (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.

蒂亚马丁

推荐答案

我不知道你说的是否完全正确.在下面的 XAML 中,TextBlock 将显示矩形的宽度.当您单击 Rectangle 时,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天全站免登陆