【发布时间】:2014-02-05 15:35:45
【问题描述】:
我正在努力使用 xaml 在情节提要的不同项目中设置附加属性。
在文本框的样式中,我有一个事件触发器,它应该在事件发生后将附加属性设置为 true。
XAML:
xmlns:MyNamespace="clr-namespace:Project.Utilities"
<EventTrigger RoutedEvent="SomeEvent">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetProperty="MyNamespace:MyClass.MyAttachedProperty">
<DiscreteBooleanKeyFrame Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
C#:
namespace MyNamespace
{
public static class MyClass
{
public static readonly DependencyProperty MyAttachedPropertyProperty
= DependencyProperty.RegisterAttached("MyAttachedProperty", typeof(bool),
typeof(MyClass), new UIPropertyMetadata(false));
public static void SetMyAttachedProperty(DependencyObject target, bool value)
{
target.SetValue(MyAttachedPropertyProperty, value);
}
public static bool GetMyAttachedProperty(DependencyObject target)
{
return (bool)target.GetValue(MyAttachedPropertyProperty);
}
}
}
使用 PropertyPath,我按照here 中的说明进行操作。 但我总是得到一个“System.InvalidOperationException”: 附加信息:无法解析属性路径“MyNamespace:MyClass.MyAttachedProperty”中的所有属性引用。验证适用的对象是否支持这些属性。
我尝试了几种不同的方法来编写带括号和不带括号的路径,但老实说,即使没有 MSDN Post 的帮助,我也不太明白如何定义路径
有谁知道我还能尝试访问附加的属性吗?
提前致谢!
【问题讨论】:
标签: c# wpf xaml properties storyboard