We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind the GridColumn.IsHidden property to property in ViewModel?

Platform: UWP |
Control: SfDataGrid |
.NET Framework: 4.5 |
Product Version:
Tags: columns

The column definitions of the DataGrid are not part of the SfDataGrid visual tree, so you can not bind SfDataGrid DataContext with GridColumn.

You can overcome this problem by defining ViewModel (DataContext) inside Resources and you can bind ViewModel to GridColumns by using StaticResource binding as in the following code example.



Here ViewModel is given as Windows Resources to access it as StaticResource for GridColumn Properties.

Another method is by using FindAncestor. In this method, ViewModel is defined as DataContext for MainWindow. You can bind MainWindow DataContext properties to GridColumns using RelativeResource. This FindAncestor is supported in WPF only.

Refer the following code example.


Here Hide property is defined in ViewModel. So you can set ancestor type as MainWindow and path as DataContext.Hide. IsHidden property value is derived from ViewModel through MainWindow DataContext.

Sample Links:





2X faster development

The ultimate UWP UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile