This is a migrated thread and some comments may be shown as answers.

Visibility of PropertyDefinations in PropertyGrid.

1 Answer 154 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
muhammad
Top achievements
Rank 1
muhammad asked on 03 Apr 2014, 10:02 AM
Hello Telerik Team,
                                 I am trying to use a single property grid for different objects to show their properties and values on the same grid. I have defined  properties for each object using Property definition. Now on object selection change or object type change I want to hide my properies defined for other objects. It does not work  if I use property from statice resource or property from my ViewModel senario. Somehow its not picking property from my ViewModel datacontext. I have attached my sample application for the scenario. Please suggest something in this respect thanks.

Regards.

UI Code.


<Window x:Class="RadGridView_WPF_AR_19.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:radGridViewWpfAr19="clr-namespace:RadGridView_WPF_AR_19"
        Title="Window1" Height="300" Width="300">


    <Window.Resources>
        <telerik:BooleanToVisibilityConverter x:Key="cnv" />
        <radGridViewWpfAr19:NewMyViewModel x:Key="vm"/>
    </Window.Resources>
    <Grid x:Name="Mygrid" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ListBox ItemsSource="{Binding Path=Objects}" SelectedItem="{Binding Path=SelectedObject,Mode=TwoWay}" DisplayMemberPath="Name" Height="100" Grid.Row="0"/>
        <telerik:RadPropertyGrid Item="{Binding SelectedObject}" Grid.Row="1" AutoGeneratePropertyDefinitions="False" x:Name="rpg">
            
            <telerik:RadPropertyGrid.PropertyDefinitions>
                <telerik:PropertyDefinition Binding="{Binding Id}" DisplayName="Id" />
                <telerik:PropertyDefinition Binding="{Binding Name}" DisplayName="Name" Visibility="{Binding Source={StaticResource vm}, Converter={StaticResource cnv}, Path=IsA}"/>
                <telerik:PropertyDefinition Binding="{Binding Name}" DisplayName="Name" Visibility="{Binding Source={StaticResource vm}, Converter={StaticResource cnv}, Path=IsB}"/>
                <telerik:PropertyDefinition Binding="{Binding Name}" DisplayName="Name" Visibility="{Binding Source={StaticResource vm}, Converter={StaticResource cnv}, Path=IsC}"/>
            
            </telerik:RadPropertyGrid.PropertyDefinitions>
            
        </telerik:RadPropertyGrid>
    </Grid>
</Window>


ViewModel and DataContext code.


namespace RadGridView_WPF_AR_19
{
    using Telerik.Windows.Controls;

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            this.DataContext = new NewMyViewModel();
        }
    }

    public class NewMyViewModel:ViewModelBase
    {
        private object selectedObject;

        private List<object> objects ;
        public List<object> Objects {
            get
            {
                return this.objects;
            }
        }

        public NewMyViewModel()
        {
            this.objects = new List<object>
                          {
                              new A{Name="A",Id=1},
                              new B{Name="B",Id=2},
                              new C{Name="C",Id=3}
                          };


        }


        public object SelectedObject {get
        {
            return this.selectedObject;
        }
            set
            {
                this.selectedObject = value;
                
                OnPropertyChanged(()=>this.SelectedObject);

                OnPropertyChanged(() => this.IsA);
                OnPropertyChanged(() => this.IsB);
                OnPropertyChanged(() => this.IsC);
            }
        }

        public bool IsA {
            get
            {
                return this.SelectedObject != null && this.SelectedObject.GetType().Name == "A";
            }
        }
        public bool IsB
        {
            get
            {
                return this.SelectedObject != null && this.SelectedObject.GetType().Name == "B";
            }
        }
        public bool IsC
        {
            get
            {
                return this.SelectedObject != null && this.SelectedObject.GetType().Name == "C";
            }
        }
    }

    public class A
    {
        public string Name { get; set; }
        public int Id {get;set;}

        public override string ToString()
        {
            return "A Class";
        }
    }
    public class B
    {
        public string Name { get; set; }
        public int Id { get; set; }

        public override string ToString()
        {
            return "B Class";
        }
    }
    public class C
    {
        public string Name { get; set; }
        public int Id { get; set; }

        public override string ToString()
        {
            return "C Class";
        }
    }
}
 
 

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 08 Apr 2014, 09:05 AM
Hello,

I have prepared a sample project based on the code snippet you provided and it seems to work as expected. Please give it a try and let me know how it works at your side.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
PropertyGrid
Asked by
muhammad
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or