gpt4 book ai didi

c# - 混合交互行为给出 "points to immutable instance"错误

转载 作者:行者123 更新时间:2023-11-30 21:20:52 25 4
gpt4 key购买 nike

我有一个 UserControl,它是其他用户控件的基类,显示在“模态视图”中。
我想让所有用户控件在显示时淡入,在关闭时淡出。我还希望用户能够四处移动控件。我的构造函数如下所示:

var tg = new TransformGroup();
tg.Children.Add(new ScaleTransform());
RenderTransform = tg;
var behaviors = Interaction.GetBehaviors(this);
behaviors.Add(new TranslateZoomRotateBehavior());

Loaded += ModalDialogBase_Loaded;

ModalDialogBase_Loaded 方法如下所示:

private void ModalDialogBase_Loaded(object sender, RoutedEventArgs e)
{
var fadeInStoryboard = (Storyboard)TryFindResource("modalDialogFadeIn");
fadeInStoryboard.Begin(this);
}

当我按下控件上的关闭按钮时,调用此方法:

protected virtual void Close()
{
var fadeOutStoryboard = (Storyboard)TryFindResource("modalDialogFadeOut");
fadeOutStoryboard = fadeOutStoryboard.Clone();
fadeOutStoryboard.Completed += delegate
{
RaiseEvent(new RoutedEventArgs(ClosedEvent));
};
fadeOutStoryboard.Begin(this);
}

淡出的 Storyboard 如下所示:

<Storyboard x:Key="modalDialogFadeOut">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="{x:Null}">
<EasingDoubleKeyFrame KeyTime="0" Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseIn" Amplitude="0.3" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseIn" Amplitude="0.3" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="{x:Null}">
<EasingDoubleKeyFrame KeyTime="0" Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseIn" Amplitude="0.3" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseIn" Amplitude="0.3" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
<EasingDoubleKeyFrame KeyTime="0" Value="1" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>

如果显示了用户控件,并且用户没有在屏幕上四处移动它,则一切正常。但是,如果用户移动控件,当 modalDialogFadeOut Storyboard启动时我会收到以下错误:

路径“(0).(1)[0].(2)”中的“子项”属性值指向“System.Windows.Media.TransformCollection”的不可变实例。

我该如何解决这个问题?

最佳答案

问题是 TranslateZoomRotateBehavior 将您的 ScaleTransform 替换为 MatrixTransform,导致 Storyboard 中的前两个动画以不再存在的属性为目标。

由于您无法为 Matrix 的值设置动画以获得淡出效果,因此我将使用额外的容器控件。行为的最外层,然后是在视觉上淡出的内部行为。

关于c# - 混合交互行为给出 "points to immutable instance"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3035363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com