16,007,809 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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.
snprani
12-May-14 2:51am
View
Hi Shai,
Here is the snap of my ViewModel which contains automatic properties. Hope this is correct way of adding properties. If not please let me know how.
public class FieldEntityViewModel :TreeViewItemViewModel
{
FieldEntity _fieldEntity;
public FieldEntityViewModel(FieldEntity fieldEntity, DocumentEntityViewModel parentDocument)
: base(parentDocument)
{
Mediator.Instance.Register(
(Object o) => { RubberbandSizeChanged((Rect)o); }, ViewModelMessages.RubberbandSizeChanged);
_fieldEntity = fieldEntity;
}
[Category("Settings")]
[DisplayName("Field Name")]
[Description("Field Name")]
public string FieldName
{
get { return _fieldEntity.FieldName; }
set
{
_fieldEntity.FieldName = value;
OnPropertyChanged("FieldName");
}
}
[Category("Settings")]
[DisplayName("Field Type")]
[Description("Is it ICR, OCR or Activity type")]
public FieldType FieldType
{
get { return _fieldEntity.FieldType; }
set
{
_fieldEntity.FieldType = value;
OnPropertyChanged("FieldType");
}
}
[Category("Location & Size")]
[DisplayName("X Position")]
[Description("X Position of the rubberband region")]
public double X
{
get { return Math.Round(_fieldEntity.X); }
set
{
_fieldEntity.X = value;
OnPropertyChanged("X");
}
}
[Category("Location & Size")]
[DisplayName("Y Position")]
[Description("Y Position of the rubberband region")]
public double Y
{
get { return Math.Round(_fieldEntity.Y); }
set
{
_fieldEntity.Y = value;
OnPropertyChanged("Y");
}
}
[Category("Location & Size")]
[DisplayName("Width")]
[Description("Width of rubberband rectangle area")]
public double Width
{
get { return Math.Round(_fieldEntity.Width); }
set
{
_fieldEntity.Width = value;
OnPropertyChanged("Width");
}
}
[Category("Location & Size")]
[DisplayName("Height")]
[Description("Height of rubberband rectangle area")]
public double Height
{
get { return Math.Round(_fieldEntity.Height); }
set
{
_fieldEntity.Height = value;
OnPropertyChanged("Height");
}
}
}
snprani
12-May-14 2:48am
View
Deleted
Hi Shai,<br>
<br>
I have added the automatic properties. Here is the code.<br>
<br>
public class FieldEntityViewModel :TreeViewItemViewModel<br>
{<br>
FieldEntity _fieldEntity; <br>
<br>
public FieldEntityViewModel(FieldEntity fieldEntity, DocumentEntityViewModel parentDocument)<br>
: base(parentDocument)<br>
{<br>
Mediator.Instance.Register(<br>
(Object o) => { RubberbandSizeChanged((Rect)o); }, ViewModelMessages.RubberbandSizeChanged);<br>
_fieldEntity = fieldEntity;<br>
<br>
}<br>
<br>
<br>
///
<br>
/// Whenever there is a change in the size of the marked field, this function is called<br>
/// to change it.<br>
///
<br>
/// <param name="rectangle"></param><br>
private void RubberbandSizeChanged(Rect rectangle)<br>
{<br>
if (rectangle == null)<br>
return;<br>
<br>
if (rectangle.IsEmpty)<br>
return;<br>
try<br>
{ <br>
Width = rectangle.Width;<br>
Height = rectangle.Height;<br>
X = rectangle.X;<br>
Y = rectangle.Y;<br>
}<br>
catch (Exception ex)<br>
{<br>
throw ex;<br>
} <br>
}<br>
<br>
///
<br>
/// Field Name<br>
///
<br>
[Category("Settings")]<br>
[DisplayName("Field Name")]<br>
[Description("Field Name")]<br>
public string FieldName <br>
{<br>
get { return _fieldEntity.FieldName; }<br>
set<br>
{<br>
_fieldEntity.FieldName = value;<br>
OnPropertyChanged("FieldName");<br>
}<br>
}<br>
<br>
///
<br>
/// Rubberband <br>
///
<br>
public Shape Rubberband<br>
{<br>
get { return _fieldEntity.Rubberband; }<br>
set<br>
{<br>
_fieldEntity.Rubberband = value;<br>
OnPropertyChanged("Rubberband");<br>
}<br>
}<br>
<br>
///
<br>
/// Field type<br>
///
<br>
[Category("Settings")]<br>
[DisplayName("Field Type")]<br>
[Description("Is it ICR, OCR or Activity type")] <br>
public FieldType FieldType<br>
{<br>
get { return _fieldEntity.FieldType; }<br>
set<br>
{<br>
_fieldEntity.FieldType = value;<br>
OnPropertyChanged("FieldType");<br>
}<br>
}<br>
<br>
///
<br>
/// X position of the rubberband rectangle area<br>
///
<br>
[Category("Location & Size")]<br>
[DisplayName("X Position")]<br>
[Description("X Position of the rubberband region")] <br>
public double X<br>
{<br>
get { return Math.Round(_fieldEntity.X); }<br>
set<br>
{<br>
_fieldEntity.X = value;<br>
OnPropertyChanged("X");<br>
}<br>
}<br>
<br>
///
<br>
/// Y position of the rubberband rectangle area<br>
///
<br>
[Category("Location & Size")]<br>
[DisplayName("Y Position")]<br>
[Description("Y Position of the rubberband region")]<br>
pu
snprani
8-May-14 3:14am
View
Hi Shai,
Thanks for your response. Here is my XAML for property grid <br>
<pre lang="c#"><xctk:propertygrid x:name="_propertyGrid" margin="10" selectedobject="{Binding}" autogenerateproperties="False">
</xctk:propertygrid></pre>
Here is .CS file
public PropertyGridUserControl()
{
InitializeComponent();
Mediator.Instance.Register(
//Callback delegate, when message is seen
(Object o) =
{
UpdatePropertyGrid((TreeViewItemViewModel)o);
}, ViewModelMessages.PropertyChange);
}
void UpdatePropertyGrid(TreeViewItemViewModel selectedItem)
{
if (selectedItem is CodeBookViewModel)
{
this.DataContext = (CodeBookViewModel)selectedItem;
}
else if(selectedItem is DocumentEntityViewModel)
{
this.DataContext = (DocumentEntityViewModel)selectedItem;
}
}
This is what i have done in the code. Still it is not showing any data in the UI.
If I add propertydefinitins for each and every view model for the grid, it is showing data.
Please help in getting into dynamically changing the viewmodel based on treeview selection.
Show More