locked
ToolboxControl - Auto Expand/Collapse RRS feed

  • Question

  • Is there a way to set the expand/collapse display mode for the ToolboxControl in code ?  We have quite a few Categories and the list would be much nicer if we could start with only one Category expanded not all of them.

    Tuesday, December 22, 2009 4:06 AM

Answers

  • I guess you are asking about a rehosted workflow designer scenario and the sapt:ToolboxControl class.

    Since you can't subclass ToolboxControl, it would have to do it by setting properties, or reacting to events on the control. I had trouble with this too, but here is the best I have so far is to make all categories collapsed by default, which I figure is at least closer to what you want:

    tbc.CategoryItemStyle = new System.Windows.Style(typeof(TreeViewItem))
    {
        Setters = {
            new Setter(TreeViewItem.IsExpandedProperty, false)
        }
    };


    (tbc is the ToolboxControl). Of course it could be done in XAML too... Maybe this will inspire someone to reach the full solution?

    • Marked as answer by Mike Oliszewski Tuesday, December 22, 2009 7:38 AM
    • Edited by Tim Lovell-Smith Wednesday, December 23, 2009 12:59 AM Formatting to get rid of scrollbars
    Tuesday, December 22, 2009 6:47 AM

All replies

  • I guess you are asking about a rehosted workflow designer scenario and the sapt:ToolboxControl class.

    Since you can't subclass ToolboxControl, it would have to do it by setting properties, or reacting to events on the control. I had trouble with this too, but here is the best I have so far is to make all categories collapsed by default, which I figure is at least closer to what you want:

    tbc.CategoryItemStyle = new System.Windows.Style(typeof(TreeViewItem))
    {
        Setters = {
            new Setter(TreeViewItem.IsExpandedProperty, false)
        }
    };


    (tbc is the ToolboxControl). Of course it could be done in XAML too... Maybe this will inspire someone to reach the full solution?

    • Marked as answer by Mike Oliszewski Tuesday, December 22, 2009 7:38 AM
    • Edited by Tim Lovell-Smith Wednesday, December 23, 2009 12:59 AM Formatting to get rid of scrollbars
    Tuesday, December 22, 2009 6:47 AM
  • Would be better if I had a way to selectively expand/contract, but this was what I needed.  The designer loads noticably faster with them defaulted to collapsed as well.

    Thank You.

    Tuesday, December 22, 2009 7:41 AM
  • Brilliant.  

    <Style x:Key="{x:Type Toolbox:ToolboxControl}" TargetType="Toolbox:ToolboxControl" >
                <Setter Property="CategoryItemStyle">
                    <Setter.Value>
                        <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                            <Setter Property="IsExpanded" Value="False" />
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>

    does it in XAML.  

    You could probably use Style Triggers to selectively Expand or Collapse different nodes, or maybe a ValueConverter.

    It does seem to override whatever the default style is (Bold, different background, etc).  I added some of that back in the style I created, but didn't match it completely.  Doesn't matter that much to me, but could be an issue for some people who want the exact same L&F.
    • Edited by Turntwo Thursday, October 4, 2012 5:59 AM
    Thursday, October 4, 2012 5:58 AM