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. (Last updated on : Nov 16th 2018).
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?

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.

XAML

 

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:

WPF

UWP

 

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
6117 01/25/2016 05/04/2016 UWP SfDataGrid 4.5 12.1.0.43
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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