Hi, I've been reading through the PropGrid manual and demos, but am stuck with what is almost certainly a total newbie issue.
I am trying to customize the categories, properties displayed and property editors in XAML, with a PropertyGrid whose SelectedObjects is set to an ArrayList of objects (all of type Person).
The following XAML is used to define the grid in the main window:
<propgrid:PropertyGrid Grid.Column="1" Name="PropertyGrid1"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<propgrid:PropertyGrid.Items>
<propgrid:PropertyGridPropertyItem DisplayName="First Name"
ValueName="FirstName" Description="First name goes here." AllowDrop="True" />
<propgrid:PropertyGridPropertyItem DisplayName="Last Name" ValueName="LasttName"
Description="Family name goes here." />
</propgrid:PropertyGrid.Items>
</propgrid:PropertyGrid>
In the following code is used in the main windows code behind.myBridge is a bridge class, which implements custom iEnumerator (so that the propgrid only sees the persons that have person.selected=true. It basically reveals a series of 'person' objects to the property grid.
What I want to be able to do is customize each of the property attributes that will display on the property grid, eg. instead of showing "FirstName" and "LastName", the user will see "First Name" and "Last Name," and I wish to have some custom property editors as well.
My challenge is that when I set PropertyGrid1.SelectedObjects = myBridge, I set a runtime error with an inner exception stating "Items collection must be empty before using ItemsSource"
Can someone please provide a bit of a walk through of how to solve this.
Best regards,
JS
I am trying to customize the categories, properties displayed and property editors in XAML, with a PropertyGrid whose SelectedObjects is set to an ArrayList of objects (all of type Person).
The following XAML is used to define the grid in the main window:
<propgrid:PropertyGrid Grid.Column="1" Name="PropertyGrid1"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<propgrid:PropertyGrid.Items>
<propgrid:PropertyGridPropertyItem DisplayName="First Name"
ValueName="FirstName" Description="First name goes here." AllowDrop="True" />
<propgrid:PropertyGridPropertyItem DisplayName="Last Name" ValueName="LasttName"
Description="Family name goes here." />
</propgrid:PropertyGrid.Items>
</propgrid:PropertyGrid>
In the following code is used in the main windows code behind.
' Load in some sample data to the bridge, with just the first and last items being person.selected =true.
' assign the propertygrid1's selectedobjects to mybridge (which calls the bridge class' customer ienumerator
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
myBridge.ActiveList.Add(New Person("Magnus", "Devine", "1234567", Now(), "Initial Data", True))
myBridge.ActiveList.Add(New Person("Joe", "Sweeney", "0249705842", Now(), "First example", False))
myBridge.ActiveList.Add(New Person("Frank", "Ferlon", "0345454322", Now(), "Second example", False))
myBridge.ActiveList.Add(New Person("Roy", "Turnbel", ")834324224", Now(), "Third example", False))
myBridge.ActiveList.Add(New Person("Cindy", "Sweeney", "0189193413", Now(), "Forth example", True))
PropertyGrid1.SelectedObjects = myBridge
End Sub
What I want to be able to do is customize each of the property attributes that will display on the property grid, eg. instead of showing "FirstName" and "LastName", the user will see "First Name" and "Last Name," and I wish to have some custom property editors as well.
My challenge is that when I set PropertyGrid1.SelectedObjects = myBridge, I set a runtime error with an inner exception stating "Items collection must be empty before using ItemsSource"
Can someone please provide a bit of a walk through of how to solve this.
Best regards,
JS
------------------------------------------ For all your label, tag and signage needs.