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, we want to implement a property editor for administration a database strucure. Therefore we have the following tables:
The editor is dependant on Property,Datatype. There will be dataypes like "Text" with large text elements. For editing we have first to display e.g. 20 characters, followed by a small button "(...)" for opening a dialog box with a large edit field. Because we have not static objects with fix properties and standard object types we have 2 non standard problems to solve. How can we realize this with our new Enterprice Edition of your PropertyGrid? Best regards!
|
|
|
I am not sure how you are generating "properties" during runtime -- I assume you mean you want the set of grid entries to be generated at runtime rather than using the static compile-time CLR properties of the object? If so, there are a couple of ways to go about this: 1. Implement ICustomTypeDescriptor on your objects to return your custom set of "properties" rather than the properties from the object's CLR type. 2. Store the properties as an ObservableDictionary<string, object> and set the grid.ItemsSource to that dictionary. 3. Create grid entries directly using the AddNode method. Based on your description my initial suggestion would be option 2, possibly using smart dictionary keys (http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1198) to support the required grouping behaviour. For customising the editor based on Property.DataType, have a look at http://www.mindscape.co.nz/blog/index.php/2008/04/30/smart-editor-declarations-in-the-wpf-property-grid/, http://www.mindscape.co.nz/blog/index.php/2008/07/15/choosing-wpf-property-grid-editors-from-code/ and http://www.mindscape.co.nz/blog/index.php/2008/12/11/smart-editors-for-the-wpf-property-grid-meet-smart-templates/. The latter describes an approach in terms of CLR properties and attributes but it is readily adaptable to smart dictionary keys if that is the way you choose to go. Hope this helps -- let us know if you need more information. |
|
|
I tried option 2 but I still have some basic problems. The Link http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1198 is just related to sorting, right? How do I the grouping? I trie to set the value object as a generice type with "value" and "goup" properties. But then I get subtrees in my propertygrid and can't edit the values. WIthout that I have another problem: if I change a property value, the event handler returns always "Item[]" for e.PropertyName. What's the problem? |
|
|
Grouping in the ItemsSource scenario is handled in the same way as in the normal reflective scenario -- set grid.Grouping or add a GroupDescription to grid.BindingView.DefaultView.GroupDescriptions. Inside your GroupDescription you can access Node.Name to find out the "property" (dictionary entry) and return an appropriate group name. See http://www.mindscape.co.nz/blog/index.php/2008/01/27/sorting-and-grouping-in-the-wpf-property-grid/ for more info. You can also get at the dictionary key by casting the Node to a CollectionElement and looking at IndexedPropertyArguments. Note that to use the smart dictionary keys idea you have to stuff extra data (such as sort order and group name) into the *key*, not the value. If you stuff extra data into the value then you will see the subtree problem. Re the property name, are you talking about the ObservableDictionary.PropertyChanged event? That will be Item[] because that is the name of the CLR-level property that is changing (just as with ObservableCollection). It sounds like you are looking for the key of the dictionary entry which is changing, which is not provided by INotifyPropertyChanged. If you need to know which entry has changed, listen for the CollectionChanged event: if this comes in with a Replace action then you can cast NewItem[0] to KeyValuePair<TKey,TValue> and get the key from there. |
|
|
I got the grouping and sorting it to work. Thanks! But if I use the toolbar function to show the items as a flat list, I can't get back the grouped display. It's just a one-way function right now. How can I fix that behaviour? |
|
|
I need another hint: how can I get the groups in a sorted order? |
|
|
You would need to create your own toolbar -- turn off the built-in toolbar and put a ToolBar or horizontal StackPanel above the grid. At present the group descriptions associated with the built-in toolbar are hardwired into the control, and the "show categorised" button always uses the baseline, unsorted grouping. We can look at providing an enhancement to allow customisation of the grouping; we can also provide a sample of how to create your own toolbar if required; let us know. |
|
|
Re sorting the groups:
Category sorting is a problem. As far as we have been able to determine, WPF collection views don’t provide a way to sort groups. The only thing we have found is to explicitly define the group names *before* applying the grouping. This would have to be done in code and would look something like this: List<string> groups = new List<string>(); PropertyGroupDescription grouper = new
PropertyGroupDescription(“Node”, new NodeToCategoryConverter()); |
|
|
When running the application and filling the propertyGrid I get tons of messages like this: System.Windows.Data Error: 16 : Cannot get 'Value' value (type 'String') from '' (type 'ObjectWrapper`1'). BindingExpression:Path=Value; DataItem='ObjectWrapper`1' (HashCode=16272906); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.Collections.Generic.KeyNotFoundException: Der angegebene Schlüssel war nicht im Wörterbuch angegeben.
Followed by lots of outputs like that: System.Windows.Data Warning: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Mindscape.WpfPropertyGrid.PropertyGrid', AncestorLevel='1''. BindingExpression:Path=SelectedGridItem; DataItem=null; target element is 'TreeListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
My application gets slower and slower each time iI fill the propertyGrid. What's wrong? |
|
|
Hmm, it sounds like we may have an issue where we are keeping data bindings or event handlers around after the data is long since dead and gone. Would it be possible for you to post a small sample with steps to reproduce the issue? Thanks! |
|
|
What I do is the following: I have a treeview and if I select a node I call fillPropertyGrid(id) to fill the observable dictionary used as item source for the datagrid. private Dictionary<Guid, DictionaryDatabase.TypePropertyDict> _propertyList = new Dictionary<Guid, DictionaryDatabase.TypePropertyDict>(); public void fillPropertyGrid(Guid itemGuid) {
<DataTemplate x:Key="LargeTextEditor">
Hope that helps finding the propblem. |
|
|
Hello cew3, Sorry it's taken a while to get back to you on this. We have reproduced the problem and are investigating. In the meantime, a workaround appears to be to replace the following line: _workingPropertyList.Clear(); with the following: _workingPropertyList = new ObservableDictionary<PropertyGridSortableKey, object>(); |
|
|
How can I set a max length for an edit field? Does this work with the masked text box? If yes, how? - or - do I have to define a template? If yes, how do I set the maxlegth dynamically?
cew3 |
|
|
I think you could do it with the masked text box by generating a mask on the fly, Alternatively you could use a custom template consisting of a normal text box and an attached behaviour. Re setting the maximum length dynamically: this depends on where the max length information comes from. In your editor declaration you can specify an EditContext which is passed to the template: this would be the way to go if you can know the max length at editor declaration time. |
|
|
I thought I could do it with the masked text box. Can you give me an example how to use it? PropertyEditor maskedTextbox = new PropertyEditor(); Do you have an example on how to use the EditContext? |
|
|
Style maskedTextBoxStyle = new Style(); The EditContext is used only with custom editor templates and would go something like this: // code // DataTemplate // MaxLengthToMaskConverter Or with an attached behaviour: // DataTemplate where MaxLength is an attached behaviour that intercepts PreviewKeyDown and throws away keystrokes beyond the specified length. |
|
|
It doesn't work in my code: Int16 len = 10; The editor doesn't cut of the chars afetr char 10 and in case of editing the text it doesn't work as expected.
What's wrong in my code? |
|
|
I found the bug why the editor was not used: the maskedTextBox.PropertyName was missing and the maskedTextBox.EditContext has to be set to the Mask (e.g."&&&&&") But now I have the problem, that the default character used to show the empty places is "_". Because I can have "_" in the data, I can't see the difference between placeholders nad data. How can I change the default chararcter to nothing |
|
|
How can I avoid these "_" to be saved?? Example: Value = "abc" Editor content = "abc_______" in case of a mask like "&&&&&&&&&&" After saving the value, I get back "abc_______" as value. That's not what I want. |
|
|
Actually, I just had a look around, and it looks like there is an easier way than using the MaskedTextBox. Instead, just use a normal TextBox and set its MaxLength property. Again, if you need to do this dynamically you can do so by using the EditContext and binding the MaxLength property. Sorry about that; that will teach me to go look in MSDN before trying to reinvent the wheel... |
|
|
Hello, i fill datatable from database and want to bind wpf grid with generic list. So how to convert datatabel to generic list. for this i want to create runtime properties. Please tell me thye solution.
Rakhi |
|
|
To create properties at runtime, implement ICustomTypeDescriptor, or use TypeConverterAttribute and override TypeConverter.GetProperties and GetPropertiesSupported. |
|