Adding tab items dynamically in WPF / MVVM

Some instructions on how to add/remove tab items within a WPF / MVVM setting. Step 1: Create a new WPF application Step 2: Add classes to implement ICommand RelayCommand.cs EventRaiser.cs EventArgs.cs Step 3: Add the ViewModel class We need a class to implement the button click events, as well contain data for tab-related information. MainWindowViewModel.cs …

Continue reading ‘Adding tab items dynamically in WPF / MVVM’ »

How to stop C# async methods

Scenario: a WPF application which when the user presses a button goes off and runs something asynchronously, so that the user is still able to interact with the user interface without it freezing. Not only that, I want to be able to stop the asynchronous operation on receipt of another button press so that it …

Continue reading ‘How to stop C# async methods’ »

Binding the visibility of DataGridColumn in WPF / MVVM

See this StackOverflow answer for the original inspiration. Notable quote: “First of all DataGridTextColumn or any other supported dataGrid columns doesn’t lie in Visual tree of DataGrid. Hence, by default it doesn’t inherit DataContext of DataGrid. But, it works for Binding DP only and for not other DP’s on DataGridColumn.” Here is an example of …

Continue reading ‘Binding the visibility of DataGridColumn in WPF / MVVM’ »