簡體   English   中英

Visibility.Collapse在WPF中不起作用

[英]Visibility.Collapse does not work in WPF

Visibility.Collapse在我的情況下不起作用。 下面是XAML。 如果我試圖隱藏lblCountrycmbCountry則在zip和練習字段之間顯示一個空格。 沒有選項可以隱藏Grid的整行。

<Grid>
    <Canvas Name="canDemographic" >

    </Canvas>
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <TextBlock Width="800" Height="50" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center"  FontFamily="Arial" FontSize="30" FontWeight="Bold" Visibility="Collapsed">
  Please review or enter your user information details:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *First Name:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Middle Name:"></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Last Name:
        </TextBlock>
        <TextBlock Name="tbEmail" Width="200" Height="30" Grid.Column="0" Grid.Row="12" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Email Address:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Address1:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="6" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Address2:"></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="7" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *City:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="8" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *State:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="9" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Zip:
        </TextBlock>
        <TextBlock Name="lblCountry" Width="200" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="10" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" *Country:" Visibility="Collapsed"="></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="11" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Practice/Affiliation:"></TextBlock>

        <!-- Input fields -->
        <TextBox Name="txtFirstName" Width="200" Height="30" 
         Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" MaxLength="20" TextChanged="txtFirstName_TextChanged" IsEnabled="True" />
        <TextBox Name="txtMiddleName" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="3" MaxLength="10" IsEnabled="True" />
        <TextBox Name="txtLastName" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="4" MaxLength="20" TextChanged="txtLastName_TextChanged" />
        <TextBox Name="txtEmail" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="12" MaxLength="100"/>
        <TextBox Name="txtAddress1" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="5" MaxLength="100" TextChanged="txtAddress1_TextChanged" />
        <TextBox Name="txtAddress2" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="6" MaxLength="100"/>
        <TextBox Name="txtCity" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="7" MaxLength="50" TextChanged="txtCity_TextChanged" />
        <TextBox Name="txtState" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="8" MaxLength="50" TextChanged="txtState_TextChanged" />
        <TextBox Name="txtZip" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="9" MaxLength="50" TextChanged="txtZip_TextChanged" />
        <ComboBox Name="cmbCountry" Width="200" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="0" Grid.Row="10" Grid.ColumnSpan="2" SelectionChanged="cmbCountry_SelectionChanged" ItemsSource="{Binding}" Visibility="Collapsed" />
        <TextBox Name="txtPractice" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="11" MaxLength="50"/>
    </Grid>
    <Button Name="btnExit" Height="30" VerticalAlignment="Bottom" Width="100" HorizontalAlignment="Left" Margin="21,0,0,12" BorderThickness="1" FontFamily="arial" Background="LightGray" FontSize="12pt" FontWeight="Bold" Click="btnExit_Click">Back</Button>
    <Button Name="btnNext" Height="30" VerticalAlignment="Bottom" Width="100" HorizontalAlignment="Right" Margin="0,0,21,12" BorderThickness="1" FontFamily="arial" Background="LightGray" FontSize="12pt" FontWeight="Bold" Click="btnNext_Click" IsEnabled="False" >Next</Button>
</Grid>
    </ScrollViewer>

我認為這種情況正在發生,因為你明確地設置行的高度(到40),所以即使行內容被折疊,它也需要40的空間。嘗試將行的Height設置為Auto

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM