2
私はWPVMでMVVMを使用しているプロジェクトに取り組んでおり、難しい状況です。MVVMを使用してContentControl WPFのコンテンツを変更しますか?
ボタンがContentControl
の内容を変更するウィンドウにButton
とContentControl
を作成すると、正常に動作します。
<Window.Resources>
<me:UserControl1ViewModel x:Key="viewModel" />
</Window.Resources>
<Grid>
<Button Content="Button"
Name="button1"
Command="{Binding Source={StaticResource viewModel}, Path=ClickCommand}" />
<ContentControl Content="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Source={StaticResource viewModel}, Path=View, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
</Grid>
しかし、私はボタンでユーザーコントロールを作成し、ボタンが作動しないContentControlに内容を変更したとき。 なぜですか?
<Window.Resources>
<me:UserControl1ViewModel x:Key="viewModel" />
</Window.Resources>
<Grid>
<v:UserControl1 />
<ContentControl Content="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Source={StaticResource viewModel}, Path=View, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
</Grid>
ContentControlに
<UserControl.Resources>
<me:UserControl1ViewModel x:Key="viewModelA" />
</UserControl.Resources>
<Grid>
<Button Content="Button"
Name="button1"
Command="{Binding Source={StaticResource viewModelA}, Path=ClickCommand}" />
</Grid>
の内容の変更に感謝を呼び出しているユーザーコントロール!
あなたは適切にINotifyPropertyChangedの実装をViewModelにしていますか? – Ekk