I have a dockpanel with two buttons inside
<Window x:Class="PracticeWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel LastChildFill="True">
<Button Name="btn1" DockPanel.Dock="Top">Button 1</Button>
<Button Name="btn2" DockPanel.Dock="Top" Visibility="Collapsed">Button 2</Button>
</DockPanel></Window>
The problem is that the button btn2 is taking part in layout even if its Visibility=”Collapsed”.I expect that the btn1 must fill the whole space.
Instead btn1 is sticking to the top position of the window.
The above code must be equivalent to
<DockPanel LastChildFill="True">
<Button Name="btn1" DockPanel.Dock="Top">Button 1</Button>
<!--
<Button Name="btn2" DockPanel.Dock="Top" Visibility="Collapsed">Button 1</Button>
-->
</DockPanel>
Why this is happening.
Vinod, in DockPanel, last item will always take the rest of the layout in DockPanel. as you have already set Top to your 1st button, Dock property on the second one will be ignored i think.
instead of using DockPanel, you might give “Grid” panel a try with AutoSize property ?