Wpf сетка и видимость - PullRequest
0 голосов
/ 05 июля 2018

Я создаю форму, которая будет отображаться для элементов управления рядом, как пример ниже. Проблема в том, что когда я устанавливаю видимость одного элемента управления как «Свернутый», другой не заполняет все окно.

<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>

Как сделать так, чтобы «Кнопка 1» заполняла все окна, когда я установил видимость кнопки 2 как свернутую?

Текущий эффект, когда оба видимы:

+---------------------+
|          |          |  
|          |          |  
|          |          |  
| Button 1 | Button 2 |  
|          |          |  
|          |          |  
|          |          |  
+---------------------+

Когда кнопка 2 свернута:

+---------------------+
|          |          |  
|          |          |  
|          |          |  
| Button 1 |          |  
|          |          |  
|          |          |  
|          |          |  
+---------------------+

Желаемая:

+---------------------+
|                     |  
|                     |  
|                     |  
|      Button 1       |  
|                     |  
|                     |  
|                     |  
+---------------------+

Ответы [ 2 ]

0 голосов
/ 05 июля 2018

U можешь попробовать,

<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>
0 голосов
/ 05 июля 2018

Как @Clemens Предложил:

UniformGrid можно сделать:

<UniformGrid Rows="1" >
    <Button>Button 1</Button>
    <Button Visibility="Visible">Button 2 </Button>
</UniformGrid>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...