WPF网格和可见性

时间:2018-07-05 11:47:00

标签: c# wpf

我正在创建一个表单,它将并排显示在控件中,例如下面的示例。 问题是,当我将一个控件的可见性设置为“ Collapsed”时,另一个控件不会填充所有窗口。

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

在将button2的可见性设置为“折叠”时,如何使“按钮1”填充所有窗口?

可见的当前效果

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

当Button2合拢时:

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

所需:

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

2 个答案:

答案 0 :(得分:1)

@Clemens建议:

public class MainForm { //... public Form form = null; public MainForm(MyControl myControl) { InitializeComponent(); //... myControl.form = (Form)this; } } 可以做到:

UniformGrid

答案 1 :(得分:0)

您可以尝试

 $value[] = $datapages->getCitationDataofquotes($var1);

                for($i=0; $i<count($value); $i++) 
                {
                    $value[$i]->newprop = 'new content';
                }