Commands from Details view of MVVM Master/Details app fail
Learning MVVM\WPF\C# by building a simple master\details app. I have a MainView which holds the MasterView, DetailView, and ControlsView. I have added buttons (ICommand) to all views. They all work properly except the one on the DetailView. The problem is the view's datacontext (DataContext="{Binding SelectedMediaItem}"). On the DetailView, if I add a main grid to hold the SelectedMediaItem grid and t开发者_运维百科hen add a button the main grid it works fine. Any ideas how I can add a button next to a textbox in the SelectedMediaItem grid? Thank You
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
精彩评论