私はWindowから派生した単純なビューを持っています。その派生クラスのコードビハインドファイルでは、ActiveDocumentという新しいDependencyPropertyを定義します。XAMLの派生クラスで定義された依存関係プロパティにバインドします
この新しいDependencyPropertyを、ビューのDataContextとして設定されているViewModelのプロパティにバインドしたいとします。
このコンストラクタをクラスコンストラクタのコードを使用して設定できますが、XAMLファイルのプロパティをバインドしようとすると、ActiveDocumentプロパティがクラスウィンドウに見つからないというエラーメッセージが表示されます。
XAMLでこれを行う正しい構文は何ですか?
【コードで更新]
MainWindowViewModel.cs
class MainWindowViewModel
{
public bool IWantBool { get; set; }
}
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new MainWindowViewModel();
InitializeComponent();
}
public static readonly DependencyProperty BoolProperty = DependencyProperty.Register(
"BoolProperty", typeof(bool), typeof(MainWindow));
}
Mainwindow.xaml
<Window x:Class="DependencyPropertyTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DependencyPropertyTest"
<!-- ERROR: BoolProperty not found on type Window. -->
BoolProperty="{Binding path=IWantBool}"
<!-- ERROR: Attachable property not found in type MainWindow. -->
local:MainWindow.BoolProperty="{Binding path=IWantBool}">
<Grid>
</Grid>
</Window>
コードを投稿してください。あなたのXAMLに 'x:Class'属性がないように見えます。 – Vlad