C# 为什么在情节提要设置动画时属性上的“设置函数”不更新

C# 为什么在情节提要设置动画时属性上的“设置函数”不更新,c#,wpf,animation,binding,inotifypropertychanged,C#,Wpf,Animation,Binding,Inotifypropertychanged,我有一个属性: double _X; public double X { get { this.Title = _X.ToString(); return _X; } set { _X = value; this.Title = _X.ToString(); // !!!! this line does not execute

我有一个属性:

    double _X;
    public double X
    {
        get {
            this.Title = _X.ToString();
            return _X; 
        }
        set { 
            _X = value;
            this.Title = _X.ToString(); // !!!! this line does not execute when property changes from storyboard
            RaisePropertyChanged("X"); }
    }
   <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="99.2" Margin="37,14,0,0" VerticalAlignment="Top" Width="98.4" RenderTransformOrigin="0.5,0.5">
        <Button.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform X="{Binding X}" Y="{Binding Y}"/>
            </TransformGroup>
        </Button.RenderTransform>
    </Button>
<Storyboard x:Key="Storyboard1" AutoReverse="True" FillBehavior="HoldEnd">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="button">
            <EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="100">
                <EasingDoubleKeyFrame.EasingFunction>
                    <CircleEase EasingMode="EaseOut"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>

</Storyboard>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows;

namespace SomeNamespace
{
    public partial class MyUserControl : UserControl, INotifyPropertyChanged
    {


        public static readonly DependencyProperty SomeDoubleProperty =
    DependencyProperty.Register("SomeDouble", typeof(Double),
        typeof(MyUserControl), new PropertyMetadata(0.0));


        public double SomeDouble
        {
            get
            {
                return (double)GetValue(SomeDoubleProperty);

            }
            set
            {
                SetValue(SomeDoubleProperty, value);
                MessageBox.Show("this msg should appear meanwhile animating!");
                // code does not execute
                RaisePropertyChanged("SomeDouble");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }




    }
}
和控件:

    double _X;
    public double X
    {
        get {
            this.Title = _X.ToString();
            return _X; 
        }
        set { 
            _X = value;
            this.Title = _X.ToString(); // !!!! this line does not execute when property changes from storyboard
            RaisePropertyChanged("X"); }
    }
   <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="99.2" Margin="37,14,0,0" VerticalAlignment="Top" Width="98.4" RenderTransformOrigin="0.5,0.5">
        <Button.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform X="{Binding X}" Y="{Binding Y}"/>
            </TransformGroup>
        </Button.RenderTransform>
    </Button>
<Storyboard x:Key="Storyboard1" AutoReverse="True" FillBehavior="HoldEnd">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="button">
            <EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="100">
                <EasingDoubleKeyFrame.EasingFunction>
                    <CircleEase EasingMode="EaseOut"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>

</Storyboard>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows;

namespace SomeNamespace
{
    public partial class MyUserControl : UserControl, INotifyPropertyChanged
    {


        public static readonly DependencyProperty SomeDoubleProperty =
    DependencyProperty.Register("SomeDouble", typeof(Double),
        typeof(MyUserControl), new PropertyMetadata(0.0));


        public double SomeDouble
        {
            get
            {
                return (double)GetValue(SomeDoubleProperty);

            }
            set
            {
                SetValue(SomeDoubleProperty, value);
                MessageBox.Show("this msg should appear meanwhile animating!");
                // code does not execute
                RaisePropertyChanged("SomeDouble");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }




    }
}
我有这个观点

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:test="clr-namespace:SomeNamespace"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Window.Resources>
        <Storyboard x:Key="Storyboard1"  >
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="SomeDouble" Storyboard.TargetName="m">
                <EasingDoubleKeyFrame KeyTime="0:0:5.4" Value="100">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CircleEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>            
        </Storyboard>
    </Window.Resources>
    <Grid>
        <test:MyUserControl x:Name="m" SomeDouble="5"></test:MyUserControl>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="311,50,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

    </Grid>
</Window>

后面的按钮代码启动故事板


属性在代码中不会改变,同时也会设置动画…

如果我理解正确,您将设置TranslateTransform的
X
属性的动画,该属性也绑定到
X
属性(您没有提到定义它的类)

即使您已经声明了双向绑定,您的方法也不会起作用。例如
TranslateTransform.X
从各种提供程序获取其值,如样式设置器、触发器、动画、值继承、属性元数据的默认值、本地值以及其他一些(其中数据绑定设置本地值)。这些提供者以特定顺序应用,即以特定顺序应用

在您的场景中,这意味着
RenderTransform.X
从数据绑定获取其本地值。启动动画时,只要动画正在运行或保持该值,有效特性值就会来自该动画。同时,属性的局部值不变,这意味着对绑定没有影响(即使是双向的)


如果您想设置
X
属性的动画,可以将其设置为a并直接设置动画。

如果我理解正确,您将设置TranslateTransform的
X
属性的动画,该属性也绑定到
X
属性(您没有提到定义它的类)

即使您已经声明了双向绑定,您的方法也不会起作用。例如
TranslateTransform.X
从各种提供程序获取其值,如样式设置器、触发器、动画、值继承、属性元数据的默认值、本地值以及其他一些(其中数据绑定设置本地值)。这些提供者以特定顺序应用,即以特定顺序应用

在您的场景中,这意味着
RenderTransform.X
从数据绑定获取其本地值。启动动画时,只要动画正在运行或保持该值,有效特性值就会来自该动画。同时,属性的局部值不变,这意味着对绑定没有影响(即使是双向的)


如果要设置
X
属性的动画,可以将其设置为a并直接设置动画。

我创建了一个自定义的依赖项属性,它不适用于代码隐藏。它似乎只对viewI的自定义依赖项属性生效,对代码隐藏不起作用。它似乎只对视图起作用