シンプルな master\details アプリを作成して MVVM\WPF\C# を学習します。MasterView、DetailView、および ControlsView を保持する MainView があります。すべてのビューにボタン (ICommand) を追加しました。DetailView のものを除いて、すべて正常に動作します。問題は、ビューのデータ コンテキスト (DataContext="{Binding SelectedMediaItem}") です。DetailView で、メイン グリッドを追加して SelectedMediaItem グリッドを保持し、メイン グリッドにボタンを追加すると、正常に動作します。SelectedMediaItem グリッドのテキスト ボックスの横にボタンを追加する方法はありますか? ありがとうございました
1 に答える
0
During my learning of MVVM\WPF\C# I sometime find it difficult to find the proper words to ask my questions. Nevertheless, I have managed to find an answer to my question.
<Grid DataContext="{Binding AA}">
<Grid DataContext="{Binding CurrentItem}">
<TextBox Text="{Binding Name}" />
</Grid>
<Button Command="{Binding SomeCommand}" />
</Grid>
This code puts the TextBox under the DataContext of "CurrentItem of AA" and the button under the DataContext of "AA". I then use rows,columns and margins to position the button next to the TextBox.
HTH
于 2011-07-27T00:22:17.673 に答える