搜索后几个小时,我来对你有所帮助:依赖项属性和绑定错误
System.Windows.Data Error: 40 : BindingExpression path error: 'Test' property not found on 'object'
我无法找到我的地方绑定错误是......
在我的主窗口,我有:
<Exec:PriceView Price="{Binding Test}"/>
<TextBlock Text="{Binding Test}"/>
在我的TextBlock上,Binding with Test属性完全正常工作。
但是对于我的PriceView控件,它不是。
PriceView.xaml
<StackPanel>
<TextBlock Text="{Binding Price}" FontSize="26" FontFamily="Arial"/>
</StackPanel>
PriceView.xaml.cs
public partial class PriceView : UserControl
{
public PriceView()
{
this.InitializeComponent();
this.DataContext = this;
}
#region Dependency Property
public static readonly DependencyProperty PriceProperty = DependencyProperty.Register("Price", typeof(float), typeof(PriceView));
public float Price
{
get { return (float)GetValue(PriceProperty); }
set { SetValue(PriceProperty, value); }
}
#endregion
}
我在做什么错? 这是来自我的Dependency Properrty吗?
更正:使用依赖属性时,从不设置视图的DataContext。 – Xcalibur37 2011-12-14 01:11:54