1
votes

I'm trying to popup a list box when a toggle button is clicked. In the code behind I work with the Visibility property and set it to Visibility.Visible. However, although the list box appears on the screen, it gets cropped to the size of the toggle box (30x30), instead of, as I wish it to, its own size (99x99).

<ToggleButton HorizontalAlignment="Left" Margin="0,0,0,0"
              VerticalAlignment="Top" Width="30" Height="30"
              Click="ButtonBase_OnClick">
  <ListBox x:Name="listBox1"
           ClipToBounds="False" 
           Visibility="Collapsed"
           HorizontalAlignment="Left"
           Height="99" 
           VerticalAlignment="Top" 
           Width="99">
    <CheckBox x:Name="checkBox3" Content="CheckBox"/>
    <CheckBox x:Name="checkBox4" Content="CheckBox"/>
  </ListBox>
</ToggleButton>

I've tried setting the property ClipToBounds to false but it didn't give much change. I also tried setting the height of the combo box to Auto. That made a scroll bar appear (a horizontal one, though, which itself was a bit unexpected) but everything was still cropped to the toggle box's bounds.

What do I need to set more? Or am I approaching it the wrong way (as in: should I define the combo box inside the toggle button's child tags for templates, trigger and what not)?

1

1 Answers

2
votes

If you don't want the listbox inside the toggle button, you should not place it inside the toggle button. Place it outside of the toggle button and it should work. Maybe you should have a look at the Expander control, that seems to do what you need. It will still not make the expanders body larger than the expander.

Something else to note: it's bad style to set fixed sizes. Try to partition your window using the containers like Grid and the various Panels and you will not need fixed sizes. If your toggle button does not have a fixed size, it could expand when the contents need expansion.