Hi,
I've created a demo project that will demonstrate my current situation and my goal.
The code and XAML are attached below.
As you could see in the picture marked as "Desired display" and in propertyGrid2 in the code I had to create a mockup classes that will display the properties.
My goal is to get the "Desired display" look by using only the "MainObject" and "PropertiesObject".
The main issues I have are:
1. I need to translate the 3 properties from "PropertiesObject": "PropertyName", "PropertyType" and "PropertyValue" into a single property (without generating a new class on run time).
2. I need to make the observable collection nested properties display the list of "PropertiesObject" (after my conversion to a single property) without the extra nested properties (like Count).
3. I don't want to use or display the "CollectionEditor".
The amount and variety of the properties in the "OtherProperties" observable collection are unknown during compile-time and change during run-time from another source.
I do not require the ability to edit the properties so they can all be read-only.
Do you have any hints on how I can accomplish my goal?
This is the code I'm using:
And this is the XAML:
Thanks in advance,
I've created a demo project that will demonstrate my current situation and my goal.
The code and XAML are attached below.
As you could see in the picture marked as "Desired display" and in propertyGrid2 in the code I had to create a mockup classes that will display the properties.
My goal is to get the "Desired display" look by using only the "MainObject" and "PropertiesObject".
The main issues I have are:
1. I need to translate the 3 properties from "PropertiesObject": "PropertyName", "PropertyType" and "PropertyValue" into a single property (without generating a new class on run time).
2. I need to make the observable collection nested properties display the list of "PropertiesObject" (after my conversion to a single property) without the extra nested properties (like Count).
3. I don't want to use or display the "CollectionEditor".
The amount and variety of the properties in the "OtherProperties" observable collection are unknown during compile-time and change during run-time from another source.
I do not require the ability to edit the properties so they can all be read-only.
Do you have any hints on how I can accomplish my goal?
This is the code I'm using:
using
System;
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Data;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Imaging;
using
System.Windows.Navigation;
using
System.Windows.Shapes;
namespace
TelerikPropertyGrid
{
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
PropertiesObject property1 =
new
PropertiesObject() { PropertyName =
"stringProperty1"
, PropertyType =
typeof
(
string
), PropertyValue=
"string 1"
};
PropertiesObject property2 =
new
PropertiesObject() { PropertyName =
"stringProperty2"
, PropertyType =
typeof
(
string
), PropertyValue =
"string 2"
};
PropertiesObject property3 =
new
PropertiesObject() { PropertyName =
"boolProperty1"
, PropertyType =
typeof
(
bool
), PropertyValue= (Boolean)
true
};
PropertiesObject property4 =
new
PropertiesObject() { PropertyName =
"boolProperty2"
, PropertyType =
typeof
(
bool
), PropertyValue = (Boolean)
false
};
PropertiesObject property5 =
new
PropertiesObject() { PropertyName =
"intProperty1"
, PropertyType =
typeof
(
int
), PropertyValue=(Int32)10 };
ObservableCollection<PropertiesObject> properties =
new
ObservableCollection<PropertiesObject>() { property1, property2, property3, property4, property5 };
MainObject main =
new
MainObject() { Name =
"john"
, Age = 25, OtherProperties = properties };
//this is the property grid I have and want to modify using only MainObject and PropertiesObject classes
PropertyGrid1.Item = main;
PropertyGrid1.Visibility = System.Windows.Visibility.Visible;
//this proeprty grid demonstrates how I want my grid to look like.
//I created the "goal*" classes in order to populate it, I don't have those in the production system
PropertyGrid2.Item =
new
GoalDisplayObject();
PropertyGrid2.Visibility = System.Windows.Visibility.Hidden;
}
}
public
class
MainObject
//exist in production
{
public
string
Name {
get
;
set
; }
public
int
Age {
get
;
set
; }
public
ObservableCollection<PropertiesObject> OtherProperties {
get
;
set
; }
}
public
class
PropertiesObject
//exist in production
{
public
string
PropertyName {
get
;
set
; }
public
Type PropertyType {
get
;
set
; }
public
object
PropertyValue {
get
;
set
; }
}
public
class
GoalDisplayObject
//doesn't exist in production
{
public
string
Name {
get
{
return
"john"
; }
set
{ } }
public
int
Age {
get
{
return
25; }
set
{ } }
public
GoalNestedProperties OtherProperties {
get
{
return
new
GoalNestedProperties(); }
set
{ } }
}
public
class
GoalNestedProperties
//doesn't exist in production
{
public
bool
boolProperty1 {
get
{
return
true
; }
set
{ } }
public
bool
boolProperty2 {
get
{
return
false
; }
set
{ } }
public
string
stringProperty1 {
get
{
return
"string 1"
; }
set
{ } }
public
string
stringProperty2 {
get
{
return
"string 2"
; }
set
{ } }
public
int
intProperty1 {
get
{
return
10; }
set
{ } }
public
override
string
ToString() {
return
""
; }
}
}
And this is the XAML:
<
Window
x:Class
=
"TelerikPropertyGrid.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:TelerikPropertyGrid"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadPropertyGrid
x:Name
=
"PropertyGrid1"
Grid.Row
=
"0"
NestedPropertiesVisibility
=
"Visible"
SortAndGroupButtonsVisibility
=
"Collapsed"
SearchBoxVisibility
=
"Collapsed"
FieldIndicatorVisibility
=
"Collapsed"
DescriptionPanelVisibility
=
"Collapsed"
/>
<
telerik:RadPropertyGrid
x:Name
=
"PropertyGrid2"
Grid.Row
=
"0"
AutoGeneratePropertyDefinitions
=
"False"
NestedPropertiesVisibility
=
"Visible"
SortAndGroupButtonsVisibility
=
"Collapsed"
SearchBoxVisibility
=
"Collapsed"
FieldIndicatorVisibility
=
"Collapsed"
DescriptionPanelVisibility
=
"Collapsed"
>
<
telerik:RadPropertyGrid.PropertyDefinitions
>
<
telerik:PropertyDefinition
Binding
=
"{Binding Name}"
DisplayName
=
"Name"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding Age}"
DisplayName
=
"Age"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding OtherProperties}"
DisplayName
=
"Other Properties"
IsExpanded
=
"True"
>
<
telerik:PropertyDefinition.NestedProperties
>
<
telerik:PropertyDefinition
Binding
=
"{Binding boolProperty1}"
DisplayName
=
"boolProperty1"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding boolProperty2}"
DisplayName
=
"boolProperty2"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding stringProperty1}"
DisplayName
=
"stringProperty1"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding stringProperty2}"
DisplayName
=
"stringProperty2"
/>
<
telerik:PropertyDefinition
Binding
=
"{Binding intProperty1}"
DisplayName
=
"intProperty1"
/>
</
telerik:PropertyDefinition.NestedProperties
>
</
telerik:PropertyDefinition
>
</
telerik:RadPropertyGrid.PropertyDefinitions
>
</
telerik:RadPropertyGrid
>
</
Grid
>
</
Window
>
Thanks in advance,