This question is locked. New answers and comments are not allowed.
Hello,
I would like to bind the IsVisible property of a GridViewDataColumn to a value in a dictionary with string indexer.
This is what I've tried, but without success
The UserControl
And the ViewModel
Thanks!
Andrea
I would like to bind the IsVisible property of a GridViewDataColumn to a value in a dictionary with string indexer.
This is what I've tried, but without success
The UserControl
<UserControl.Resources> <vm:HumanResourcesModelViewModule x:Key="ViewModel"/> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource ViewModel}"> <telerik:RadGridView AutoGenerateColumns="False" HorizontalAlignment="Left" Name="radGridView1" VerticalAlignment="Top" ItemsSource="{Binding Users}" > <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" IsVisible="{Binding [Name], Source={StaticResource ViewModel}}" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Surname}" Header="Surname" IsVisible="{Binding [Surname], Source={StaticResource ViewModel}}" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Phone}" Header="Phone" IsVisible="{Binding Visibilities[Phone], Source={StaticResource ViewModel}}" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid>public class HumanResourcesModelViewModule { private ObservableCollection<User> users; public ObservableCollection<User> Users { get { return users; } set { users = value; } } public HumanResourcesModelViewModule() { users = new ObservableCollection<User> ( ); User u = new User ( ); u.Name = "Test"; u.Surname = "Prova"; u.Phone = "0331973166"; u.Visibilities.Add("Name",true); u.Visibilities.Add("Surname", true); u.Visibilities.Add("Phone", false); users.Add ( u ); } public class User : INotifyPropertyChanged { private Dictionary<string, bool> visibilities = new Dictionary<string, bool> ( ); public string Name { get; set; } public string Surname { get; set; } public string Phone { get; set; } public Dictionary<string, bool> Visibilities { get { return this.visibilities; } set { if ( this.visibilities != value ) { visibilities = value; this.RaisePropertyChanged ( "Visibilities" ); } } } public bool this[string columnName] { get { return visibilities[columnName]; } set { visibilities[columnName] = value; this.RaisePropertyChanged ( columnName ); } } protected virtual void RaisePropertyChanged ( string propertyName ) { var handler = PropertyChanged; if ( handler != null ) { handler ( this, new PropertyChangedEventArgs ( propertyName ) ); } } protected virtual void RaisePropertyChanged ( object o, PropertyChangedEventArgs e ) { var handler = PropertyChanged; if ( handler != null ) { handler ( o, e ); } } public event PropertyChangedEventHandler PropertyChanged; } }Thanks!
Andrea
