DockPanel LIFO scrollable
-
Hi there. I have a stack of buttons in a dockpanel because i need that the last button to get the stack to stay on the top (like LIFO). That's why DockPanel.Dock="Bottom" and LastChildFill="False". The goal is the first button (Button1) is on bottom and the last (Button5) stays on top. Like this code: <!-- <DockPanel LastChildFill="False"> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </DockPanel> --> My problem starts when dynamically i insert one more button and the space available on the dockpanel is not big enough. The last button disapears (and i have no more space to get the dockpanel bigger). The problem is solved when i put a ScrollViewer and a ItemsControl. Like this: <DockPanel LastChildFill="False"> <ScrollViewer> <ItemsControl> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </ItemsControl> &nb
-
Hi there. I have a stack of buttons in a dockpanel because i need that the last button to get the stack to stay on the top (like LIFO). That's why DockPanel.Dock="Bottom" and LastChildFill="False". The goal is the first button (Button1) is on bottom and the last (Button5) stays on top. Like this code: <!-- <DockPanel LastChildFill="False"> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </DockPanel> --> My problem starts when dynamically i insert one more button and the space available on the dockpanel is not big enough. The last button disapears (and i have no more space to get the dockpanel bigger). The problem is solved when i put a ScrollViewer and a ItemsControl. Like this: <DockPanel LastChildFill="False"> <ScrollViewer> <ItemsControl> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </ItemsControl> &nb
I would use a Grid, its the container of champions.
Sacha Barber
- Microsoft Visual C# MVP 2008/2009
- Codeproject MVP 2008/2009
Your best friend is you. I'm my best friend too. We share the same views, and hardly ever argue My Blog : sachabarber.net
-
Hi there. I have a stack of buttons in a dockpanel because i need that the last button to get the stack to stay on the top (like LIFO). That's why DockPanel.Dock="Bottom" and LastChildFill="False". The goal is the first button (Button1) is on bottom and the last (Button5) stays on top. Like this code: <!-- <DockPanel LastChildFill="False"> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </DockPanel> --> My problem starts when dynamically i insert one more button and the space available on the dockpanel is not big enough. The last button disapears (and i have no more space to get the dockpanel bigger). The problem is solved when i put a ScrollViewer and a ItemsControl. Like this: <DockPanel LastChildFill="False"> <ScrollViewer> <ItemsControl> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </ItemsControl> &nb
Are the DockPanel.Dock items ignored? The buttons are children of the ItemsControl which is a child of the ScrollViewer, only the ScrollViewer is a child of the DockPanel
-
Hi there. I have a stack of buttons in a dockpanel because i need that the last button to get the stack to stay on the top (like LIFO). That's why DockPanel.Dock="Bottom" and LastChildFill="False". The goal is the first button (Button1) is on bottom and the last (Button5) stays on top. Like this code: <!-- <DockPanel LastChildFill="False"> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </DockPanel> --> My problem starts when dynamically i insert one more button and the space available on the dockpanel is not big enough. The last button disapears (and i have no more space to get the dockpanel bigger). The problem is solved when i put a ScrollViewer and a ItemsControl. Like this: <DockPanel LastChildFill="False"> <ScrollViewer> <ItemsControl> <Button Name="button1" DockPanel.Dock="Bottom">Button1</Button> <Button Name="button2" DockPanel.Dock="Bottom">Button2</Button> <Button Name="button16"DockPanel.Dock="Bottom">Button3</Button> <Button Name="button3" DockPanel.Dock="Bottom">Button4</Button> <Button Name="button4" DockPanel.Dock="Bottom">Button5</Button> </ItemsControl> &nb
The buttons are being reordered because they are no longer children of the DockPanel. Instead the ItemsControl is now ordering the buttons. I would suggest using a StackPanel inside of a ScrollViewer and just inserting the new button as the first child.
<ScrollViewer>
<StackPanel Name="spButtons">
<Button Name="button4">Last added, on top</Button>
<Button Name="button3">Next to last</Button>
<Button Name="button2">Second</Button>
<Button Name="button1">First added, on bottom</Button>
</StackPanel>
</ScrollViewer>Then you can add new buttons on top like this:
spButtons.Children.Insert(0, buttonToAdd)