Reputation: 305
In my window I have a DockPanel
with a StackPane
l holding a custom UserControl on the left, and a Grid with a ListBox on the right. My UserControl contains an Expander
with a ListBox.
This is the code from the window:
<Window ...>
<DockPanel>
<StackPanel Width="100" DockPanel.Dock="Left">
<localp:NeumesPanel/> <!-- This is the UserControl -->
</StackPanel>
<Grid Margin="10" DockPanel.Dock="Right">
<ListBox .../>
</Grid>
</DockPanel>
</Window>
Right now, when I expand the Expander, part of it doesn't show since the StackPanel's Width is narrower than the Width of Expander's content. Like this: http://screenshooter.net/100101493/xfcfxau
What I'd like to achieve is to have the Expander show over my Grid without compromising on the Grid's Width - I don't want the StackPanel wider than it currently is. How to do it? Is it possible?
Upvotes: 1
Views: 2952
Reputation: 69985
As I mentioned in my comment, using the StackPanel
there could cause you problems as they don't resize their children like Grid
s do. Furthermore, a StackPanel
won't let you display content outside its bounds. The Canvas
control on the other hand will, if you set the ClipToBounds
property to False
.
Here is a very simple example that shows how you can do this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Canvas Background="Blue" Width="100" ClipToBounds="False">
<Border Background="Red" Width="200" Height="50" Panel.ZIndex="10" />
</Canvas>
</Grid>
Upvotes: 1
Reputation: 1440
Karl Shifflet has done something like that: Expander with popup
Summary of the solution:
- Wrap the
Expander
control inside aCanvas
control.- Constrain the
Canvas
height to the desired height when theExpander
control is collapsed.- Set the
Canvas
Panel.ZIndex
higher than controls you want to overlay.- Style and design your
Expander
Content
so that it looks like aPopUp
.
Edit:
In your case, you need to set the Panel.ZIndex
on the StackPanel
containing your UserControl
.
Upvotes: 4