Windows Storeの分割アプリで、ビューモデルをページからユーザーコントロールに渡したい。シナリオは、ビューのようなUserControlを使用して、いくつかの一般的なxamlを複数のページで再利用したいというものです。
メインページ:
<common:LayoutAwarePage
...
DataContext="{Binding ViewModel, RelativeSource={RelativeSource Self}}"
... >
<views:MyUserControlView Model="{Binding ViewModel}" />
...
ユーザー制御コードの場合:
public sealed partial class MyUserControlView : UserControl
{
public static readonly DependencyProperty ModelProperty =
DependencyProperty.Register("Model", typeof(MenuSource),
typeof(MyUserControlView), null);
...
public ModelType Model
{
get
{
return this.GetValue(ModelProperty) as ModelType ;
}
set
{
this.SetValue(ModelProperty, value);
}
}
モデルセッターが呼び出されることはありません。ユーザーコントロールを親ページのビューモデルに接続するにはどうすればよいですか?
または、ページで使用するための共有ビューを実装するためのより良い方法はありますか?
ありがとう。
-ジョン