Click here to Skip to main content
15,896,207 members

Comments by snprani (Top 8 by date)

snprani 19-May-14 8:23am View    
Yes. That is been called, and i am able to see the Properties as i have added propertydefinitions in the same method. Automatic properties are not working though.
snprani 16-May-14 6:58am View    
I have to change the DataContext based on a node selected in the treview. Parent node contains CodeBookViewModel, 2nd level contains DocumentViewModel like that i have 4 levels altogether.

I will paste the code for Propertygrid usercontrol. The main window contains this usercontrol in it. By default this usercontrol is getting the MainViewModel as its DataContext(nothing assinged but parent datacontext is received by all child controls). On selection of node in treeview, using Messenger , i am telling propertygrid to change its DataContext by passing appropriate object for it.

Here is the code. I am unable to share the files directly so copy pasting the code here.

PropertyGridUserControl.xaml.cs
public partial class PropertyGridUserControl : UserControl
{
string[] codeBookProperties = { "CodeBookName", "CodeBookDescription", "TemplateImageFolder" };
string[] docSetProperties = { "DocSetName", "DocSetDescription", "OriginalImagePath" };
string[] fieldProperties = { "DisplayName", "FieldName", "FieldType", "X", "Y", "Width", "Height", "SubFieldAvailable", "LexiconText", "RegexFileName", "SelectedDataType","DataTypes" };
string[] subFieldProperties = { "SubFieldName", "FieldType", "X", "Y", "Width", "Height", "SelectedDataType", "DataTypes" };

public PropertyGridUserControl()
{
InitializeComponent();

Mediator.Instance.Register(
//Callback delegate, when message is seen
(Object o) =>
{
UpdatePropertyGrid((TreeViewItemViewModel)o);
}, ViewModelMessages.PropertyChange);

_propertyGrid.PropertyDefinitions = new PropertyDefinitionCollection();
}

void GetPropertyItem(string[] Properties)
{
PropertyDefinition item = new PropertyDefinition();
item.TargetProperties = Properties;

_propertyGrid.PropertyDefinitions.Add(item);
}

///
/// Change the propertygrid elements based on Treeview selected item.
///

/// <param name="selectedItem"></param>
void UpdatePropertyGrid(TreeViewItemViewModel selectedItem)
{
if (selectedItem is CodeBookViewModel)
{
// this.DataContext = (CodeBookViewModel)selectedItem;

GetPropertyItem(codeBookProperties);
_propertyGrid.SelectedObject = selectedItem;
}
else if (selectedItem is DocumentEntityViewModel)
{
//this.DataContext = (DocumentEntityViewModel)selectedItem;

GetPropertyItem(docSetProperties);
_propertyGrid.SelectedObject = selectedItem;
}
else if (selectedItem is FieldEntityViewModel)
{
//this.DataContext = (FieldEntityViewModel)selectedItem;

GetPropertyItem(fieldProperties);
_propertyGrid.SelectedObject = selectedItem;
((FieldEntityViewModel)selectedItem).DataTypes = XMLOperation.GetDataTypes();

}
else if (selectedItem is SubFieldEntityViewModel)
{
//this.DataContext = (SubFieldEntityViewModel)selectedItem;

GetPropertyItem(subFieldProperties);
_propertyGrid.SelectedObject = selectedItem;
}
}
}

PropertyGridUserControl.xaml
<grid>
<xctk:propertygrid x:name="_propertyGrid" margin="10" selectedobject="{Binding}"
="" autogenerateproperties="False">



Hope this gives you clear idea, what i am trying to explain. Let me know otherwise. Thanks for your replies.
snprani 16-May-14 1:34am View    
Your solution is working perfectly. In my application, i have to change the DataContext based on TreeView. There it is not showing any data in the property grid.
snprani 15-May-14 5:02am View    
I am not able to see properties in PropertyGrid with the code I have shared. Automatic properties are not working for me. Please help me.
I tried to create propertydefinitions directly from .cs file then i can see the properties.
snprani 15-May-14 4:59am View    
Deleted
I am not able to see properties in PropertyGrid with the code I have shared. Automatic properties is not working for me. Please help me. And I tried to create a combobox to display list of strings and want to get the selected element using ITypeEditor. But unable to keep the selected value in it.