Reputation: 523
I am using a WPF Application, In that application I am using a telerik gird and also i am using MVVM mpdel to bind data in yjay grid. I want to disable or gray out a particular column in that grid based on my bool value. I set IsEnabled Property as false for that GridViewDataColumn but its not get affected on that column....
Please Can anyone tell me the solution of this problem?
Thanks in Advance....
My code for disabling the grid Column is:
<telerik:GridViewDataColumn Width="40" IsFilterable="False" HeaderTextAlignment="Center" Header="Max" DataMemberBinding="{Binding Constraint.MaxCountConstraint, Mode=TwoWay}" IsEnabled="{Binding MyBoolValue}" Tag="Exclude" />
Upvotes: 2
Views: 1307
Reputation: 1258
The new IsReadOnlyBinding should do the trick.
<telerik:GridViewDataColumn Width="40" IsFilterable="False" HeaderTextAlignment="Center" Header="Max" DataMemberBinding="{Binding Constraint.MaxCountConstraint, Mode=TwoWay}" IsReadOnlyBinding="{Binding MyBoolValue}" Tag="Exclude" />
Upvotes: 1
Reputation: 14700
I was bitten by this just yesterday. My problem was with the built-in WPF DataGrid, but I think it's the same root cause.
The basic problem is that your GridViewDataColumn is a virtual construct. It isn't actually displayed on-screen. What IS displayed is the data in it - the cells for the header, the cells for the data, etc. This means that the GridViewDataColumn isn't part of the visual tree for the window it's in, so the binding to your default view's DataContext fails. If you look at Visual Studio's Output pane, you'll see binding errors for this.
I found the solution in Thomas Levesque's blog, and it's a bit of a hack, but it works perfectly. It involves creating a small class called BindingProxy
which inherits Freezable
, a WPF base class that allows data contexts to venture beyond the visual hierarchy. You create a BindingProxy
as a StaticResource in your view and bind it to your datacontext, and then have your GridViewDataColumn bind to the proxy.
Check out the link, I pretty much copied the code samples verbatim, and it worked like a charm.
Upvotes: 0