-1

I have a StackPanel that has two Items: ToggleButton and ListBox. To make the listBox looks like it's a part of the toggle button -by hiding the sharp edges

enter image description here

I'm thinking to give it negative margin so it moves upward, but this presumes that it's positioned under the StackPanel which is not the case, and when I give it negative margin it covers the button. So is there a way to control how items inside StackPanel are stacked over each other, something like Z-Index in CSS?

mshwf
  • 7,009
  • 12
  • 59
  • 133
  • 1
    https://stackoverflow.com/questions/4824518/why-zindex-is-not-considered-in-arrange-override-of-a-stackpanel That might help? – Josh Feb 06 '18 at 14:53

1 Answers1

1

There is a Panel.ZIndex attached property. Set it to a larger value for the ToggleButton if you don't want the ListBox to cover it:

<StackPanel>
    <ToggleButton Content="Toggle" Panel.ZIndex="1" />
    <ListBox Margin="0 -10 0 0" Panel.ZIndex="0">
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
    </ListBox>
</StackPanel> 
mm8
  • 163,881
  • 10
  • 57
  • 88