This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, Currently I have my WPF Property Grid like this,
Which is nothing but having ObservableDictionary and the entries are of type Person. I just want to do a minimal change - That is, I want to display something like this, Person Contact aaa@ddd.com Id chich308 Name Jack eliminating the Property.ToString() which is displayed as MindscapeGrid.Person And also, Person class looks like this, public class Person I saw the Templating example, but its way too complex for me and also am not able to get the parts of the Grid properly. Like what is the part of the grid where Person is printed (key) - is it the Header? And then what follows them? Is it GridViewCollection? So, If I have customize what I want in the Header (assuming that is header), how do I handle it? Thanks, |
|
|
It sounds like you're asking about two things here: how to change the caption (from Person0 etc. to Person), and how to get rid of the default ToString() display. To get rid of the default ToString() display, use a type editor. The trick is to create a read-only data template (e.g. TextBlock Text={Binding Name}), and set the TypeEditor.AllowExpand property to true. (You can of course create a completely blank template, e.g. TextBlock Text=" ", if you prefer, which has the advantage that it can be reused for any type you want to blank out.) Changing the caption is a bit more work and, in the current version, does require you to go into templating. The "Poppy" sample in the Templating project is probably the best starting point for this because it shows how to reproduce the default grid appearance using a TreeListView and two GridViewColumns. (You'll probably want to get rid of the animated bright orange GroupStyle though. *grin* And once you've done that the sample should look a lot less intimidating!) Having got this, you can then change the CellTemplate of the first GridViewColumn (called "PropertyNameCellTemplate" in Poppy) to produce whatever caption you want. In your case, the easiest solution is probably to keep the TextBlock-based template but change the binding as follows: 1. Create an IValueConverter which takes a Node and returns a string. The default behaviour of the converter would be to return the Node's HumanName property, but if the Node's PropertyType were Person it would return "Person" instead. (You could of course put this mapping into properties of the converter rather than hardwiring it into the code.) 2. In the DataTemplate, change Text="{Binding Node.HumanName}" to Text="{Binding Node, Converter={...}}". Hope this is clear -- if not let me know. |
|
|
[quote user="ivan"]
To get rid of the default ToString() display, use a type editor. The trick is to create a read-only data template (e.g. TextBlock Text={Binding Name}), and set the TypeEditor.AllowExpand property to true. (You can of course create a completely blank template, e.g. TextBlock Text=" ", if you prefer, which has the advantage that it can be reused for any type you want to blank out.) [/quote] Excellent! Thanks Ivan! Now I have like this,
I just followed your explanation with the Editors project in the Samples Just added a DataTemplate, <DataTemplate x:Key="ChaksTemplate"> And, <my:PropertyGrid Name="MyGrid" Grid.Row="4" Width="Auto" Height="Auto"> Cool, first step in customization I
am really learning WPF DataBinding, so it will take time some time to
accomplish my second task of the other thing you have described in the
post I will update this thread as and when I progress |
|