【发布时间】:2011-07-22 20:57:51
【问题描述】:
我有一个用户控件,我想在其中公开一个名为 ExpressionText 的属性,并在 xaml 可以为该属性定义一个绑定。 所以我创建了一个依赖属性
public static readonly DependencyProperty EditorText =DependencyProperty.Register("EditorText", typeof(string), typeof(MyUerControl));
和
public string ExpressionText
{
get
{
return (string)GetValue(EditorText);
}
set
{
SetValue(EditorText, value);
}
}
在 xaml 中我这样做了。
<controls:MyUerControl x:Name="textEditor" ExpressionText="{Binding
Path=Expression,Mode=TwoWay}" />
但我明白了
无法在 MyUserControl 类型的 ExpressionText 属性上设置绑定。可以设置绑定 仅在依赖对象类型错误的依赖属性上。
我的方法有问题吗?我该如何解决这个问题?
【问题讨论】:
标签: c# wpf data-binding user-controls dependency-properties