バインディング、私はあなたの助けに来る:依存プロパティと検索の時間後にエラー
System.Windows.Data Error: 40 : BindingExpression path error: 'Test' property not found on 'object'
私のバインディングにエラーがあった場所...
私が持っている私のメインウィンドウでは、私が見つけませんでした:
<Exec:PriceView Price="{Binding Test}"/>
<TextBlock Text="{Binding Test}"/>
私のTextBlockでは、Testプロパティを使ったBindingは完全に機能しています。
しかし、私の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
どうしてですか?私は成功裏に両方を同時に使用しました。 RelativeSourceまたはElementNameを使用して別のソースを指定しない限り、DataContextを設定すると、同じレベルの他のバインディングは同じコンテキストを使用することを理解する必要があります。 – surfen