Using MVVM pattern, In front-end UI(View) designer was doing designing, who are taking responsibility of binding object?
Rajanikant Hawaldar
đŻ So, who is responsible for binding the object (ViewModel) to the View?â The Developer (or MVVM infrastructure) is responsible for setting the DataContext â not the UI Designer.The UI Designer designs the UI using XAML and defines the binding paths like:
But these bindings wonât work unless the ViewModel is assigned to the Viewâs DataContext â and this is typically handled by the developer.
đ§ How the Developer Sets the Binding (via DataContext):Option 1: Code-Behind (commonly used in smaller apps)
public partial class MainWindow : Window{ public MainWindow() { InitializeComponent(); this.DataContext = new MainViewModel(); // đ Binding happens here }}
Option 2: ViewModelLocator (preferred in MVVM frameworks like Prism or MVVM Light)