【问题标题】:Visibility.Collapsed is not giving back its spaceVisibility.Collapsed 没有归还其空间
【发布时间】:2011-11-02 14:40:52
【问题描述】:

奇怪的主题让我解释一下:我有一个 Silverlight MainPage,页面顶部有一个边框控件,高度为 400。一旦用户通过身份验证,我就会导航到一个子页面。我还折叠了 MainPage 上的边框。子页面显示正确,但其上方有一个空白 400 空间,MainPage 边框控件在折叠之前。我认为 Visibilty.Collapsed 应该交还它占据的空间,但它似乎没有这样做。我在 MainPage 中的框架对象上设置了 VerticalAlignment='Top' 并在子页面上尝试了该设置,但都不起作用。

有人有什么建议吗?谢谢

代码更新:

 <ScrollViewer>
    <Grid x:Name="LayoutRoot"
          DataContext='{StaticResource ViewModel}'>
        <Grid.RowDefinitions>
            <RowDefinition Height='400'></RowDefinition>
            <RowDefinition Height='*'></RowDefinition>
        </Grid.RowDefinitions>

【问题讨论】:

  • 显示 Xaml。您可能忽略了某些东西。
  • 好的 - 在 MainPage 上(部分 xaml 因为回答时的字符限制)
  • 您需要在“页面顶部的边框控件”周围显示 Xaml,因为包含它的网格可能具有固定大小的行。您可以编辑原始问题吗?
  • @greg - 请在问题中编辑代码。
  • HiTech - 你明白了:

标签: silverlight xaml silverlight-4.0


【解决方案1】:

您应该能够通过将边框包裹在网格中然后将包含边框的 RowDefinition 的高度设置为 Auto 来解决此问题。以下测试示例对我有用:

<Grid x:Name="MainGrid" Height="760" VerticalAlignment="Top" Background="Azure">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition x:Name="HeaderRow"  Height="Auto"></RowDefinition>
        <RowDefinition x:Name="TabRow" Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <Border BorderThickness="1" Grid.Row="0" Background="Bisque" 
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Name="HeaderBorder"
                        CornerRadius="10">
        <TextBlock>Test</TextBlock>
    </Border>
    <TextBlock Grid.Row="1">Test2</TextBlock>
    <Button Grid.Row="2" Content="Hide Border" Click="Button_Click"></Button>

</Grid>

在后面的代码中:

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
    HeaderBorder.Visibility = Visibility.Collapsed;
}

【讨论】:

    猜你喜欢
    • 2010-10-27
    • 2014-01-27
    • 2013-09-13
    • 2022-06-14
    • 2012-08-11
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多