作为 XAML 元素的附加属性
我有一类附加属性:
public static class XamlProps
{
#region Attached Properties
private static readonly DependencyProperty FooProperty = DependencyProperty.RegisterAttached(
"Foo",
typeof(string),
typeof(XamlProps),
null);
public static void SetFoo(DependencyObject obj, string action)
{
obj.SetValue(FooProperty, action);
}
}
我在 XAML 中使用这些属性:
<Border me:XamlProps.Foo="Foo to the Bar">
但现在我想在这个属性中使用更大的值,所以我想将它用作元素:
<Border>
<me:XamlProps.Foo>Foo to the Bar</me:XamlProps.Foo>
</Border>
但现在 Silverlight 不调用 SetFoo () 不再了。我该如何让它发挥作用?
在 Windows Phone 7 上(如果有的话)。
I've got a class of attached properties:
public static class XamlProps
{
#region Attached Properties
private static readonly DependencyProperty FooProperty = DependencyProperty.RegisterAttached(
"Foo",
typeof(string),
typeof(XamlProps),
null);
public static void SetFoo(DependencyObject obj, string action)
{
obj.SetValue(FooProperty, action);
}
}
And I use these properties in my XAML:
<Border me:XamlProps.Foo="Foo to the Bar">
But now I want a larger value in this property, so I'd like to use it as an element:
<Border>
<me:XamlProps.Foo>Foo to the Bar</me:XamlProps.Foo>
</Border>
But now Silverlight doesn't call SetFoo() anymore. How do I get this to work?
On Windows Phone 7 if it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用该语法,则需要指定类型:
其中 sys 命名空间映射到 System.您还需要定义 GetFoo ...
可能是复制粘贴拼写错误,但在注册中
应该是
You'll need to specify the type if you use that syntax:
Where the sys namespace maps to System. You also need to define GetFoo ...
Probably a copy-paste typo, but in the registration
should be
您永远不应该依赖被调用的 SetFoo。任何东西都可以简单地调用 SetValue(FooProperty, "blah") 并绕过它。
您应该在您的DependencyProperty。注册调用即可收到通知的变化。
You should never rely on the SetFoo being called. Anything can simply call SetValue(FooProperty, "blah") and bypass it.
You should define a PropertyChangedCallback in your DependencyProperty.Register call to be notified of changes.