Reputation: 4425
I'm creating a form, that will display to controls side-by-side, like example bellow. The problem is that when I set visibility of one control to "Collapsed", the other one does not fill all window.
<Window x:Class="Example"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Height="600" Width="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button>Button 1</Button>
<Button Grid.Column="1" Visibility="Visible">Button 2</Button>
</Grid>
</Window>
How can I make "Button 1" to fill all window, when I set button2 visibility to collapsed?
Current effect when both visible:
+---------------------+
| | |
| | |
| | |
| Button 1 | Button 2 |
| | |
| | |
| | |
+---------------------+
When Button2 is collapsed:
+---------------------+
| | |
| | |
| | |
| Button 1 | |
| | |
| | |
| | |
+---------------------+
Desired:
+---------------------+
| |
| |
| |
| Button 1 |
| |
| |
| |
+---------------------+
Upvotes: 2
Views: 256
Reputation: 71
U can try,
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button>Button 1</Button>
<Button Grid.Column="1" Visibility="Visible">Button 2</Button>
</Grid>
Upvotes: 1
Reputation: 1918
As @Clemens Suggested:
UniformGrid
can do:
<UniformGrid Rows="1" >
<Button>Button 1</Button>
<Button Visibility="Visible">Button 2 </Button>
</UniformGrid>
Upvotes: 1