If WPF MVVM is supposed to have no code behind, why does when you use the ICommand, do you need the DataContext property instantiated in the Window.xaml.cs code behind? I've watched and followed side by side YouTube WPF MVVM, data binding, ICommand, INotifyPropertyChanged videos and am confused.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new ViewModel.VM_CalcRblAmt();
}
}
How to use the view model, model, command classes with data binding in the Window.Resource tag? If that is the correct mvvm pattern? Something like this below (but does not work)in the Window.Resource tag? I ask this because going side by side on WPF MVVM tutorials from different Authors, I do not see how to plug the view model, model, and Command classes into an xml namespace in the UI(Window in this case). For example below:
<Window...
xmlns:nsviewmodel="clr-namespace:Wpf_MVVVM_Rbr.ViewModel" />
<Window.Resources>
<nsrbrvm:RbrCoreViewModel x:Key="objRbrTemp"
<Button x:Name="btnRebalancer"
Command="{Binding CalcRbrAmtCommand}"
Content="Rebalance"/>
<TextBox x:Name="txtAmtDaily" Text="{Binding model_Rblr_Temp.AmtDaily, UpdateSourceTrigger=PropertyChanged}" />
</Window.Resources>
The above code, again, is not actually between the Window.Resources tags currently. It is in the UI XAML code outside the Window.Resources tags. Which currently does work. But does not the MVVM pattern require it in Window.Resources or Page.Resources tags referencing an xmlns namespace and giving it an x:Key="someKeyName" and using data binding inside the Resources tags?
So if this is the right MVVM practice, how do I put Window.Resources data binding, view model, command, and model classes together using data binding?
Thanks in Advance! Sincerely, Me