Posts

Showing posts with the label DataGridColumn

Binding the visibility of DataGridColumn in WPF / MVVM

Image
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 how to achieve this in a Visual Studio WPF application. Step 1: Create a Visual Studio WPF application: Step 2: Create a Freezable class "Freezable objects can inherit the DataContext even when they’re not in the visual or logical tree. So, we can take advantage of that to our use. First create class inheriting from Freezable and Data DP which we can use to bind in XAML". BindingProxy.cs [code language="csharp"] using System.Windows; namespace DataGridColumnVisibility { public class BindingProxy : Freezable { public static readonly DependencyProperty DataProperty = ...