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
|
Is it possible to expand objects in the source code? I have a multilevel document with multiple expandable objects. I want to expand the first one or two levels when the document is opened. (See attachments) Please Help ;) |
|
|
Could only attach one file at a time... |
|
|
This isn't directly possible. However, I think you could do it by locating the TreeListView in the default template and setting the TreeViewItem.IsExpanded property on the required items. This would look something like this (warning: NOT TESTED, and error checking omitted!): TreeView tv = pg.Template.FindName("PART_Grid", pg) as TreeView; Note that you would need to be very careful if trying to expand multiple levels, or if trying to expand immediately after setting SelectedObject, because the UIElements (TreeViewItems) don't actually get generated until after the data binding is processed. (If the elements haven't been generated yet, this will manifest as ContainerFromItem returning null.) You may need to experiment with deferring expansion until the application is idle using Dispatcher.BeginInvoke with a DispatcherPriority, or even a timer. |
|
|
Hi Ivan, have you ever tested your code? Expanding sub level nodes does never work for me, even using dispatcher or timer. ContainerFromItem does always return null for child rows. i am trying to expand nodes automatically when their HumanName is in a given collection: m_Expanded. Sample code:
private void ExpandRememberedNodes(PropertyGridRow row) {
thanks for help. k.
|
|
|
Well, that bit of code did have a disclaimer on it saying "warning: NOT TESTED" *grin*. But I've tested it now and it works fine. The reason your fragment doesn't work is that you're always asking the top-level tree's ItemContainerGenerator to give you the container for the data item. The tree only creates containers for the top-level items; those containers then create further containers for the nested items. So when you want the container for a sub-item, you have to ask its immediate parent container. So when you recurse into ExpandRememberedNodes, you need to be passing in the parent container as well as the parent data item (row). This parent container will initially be the TreeView, but on subsequent recursive calls it will be the TreeViewItem that you just found. As you're aware, you also have an issue where the child items don't get created until WPF data binding runs, i.e. asynchronously, so you can't make the recursive call immediately: you need to hand it off to the dispatcher, to run after binding. Here's how it looks (again, error checking omitted): private void Expand(PropertyGridBindingView rows, ItemsControl parent, Predicate<PropertyGridRow> criterion) And here's how I call it: private void ExpandPartner() (Obviously your criterion predicate will be m_Expanded.Contains(row.Node.HumanName).) This works for me -- let me know if you still see problems. |
|
|
Hi Ivan, it works perfectly. Thank you for your help. k.
|
|
|
For anyone reading this thread, the latest nightly build of WPF Elements 6.0 includes an ExpanderMode property on the PropertyGrid which when set to Expanded will expand all items on startup. Jason Fauchelle |
|