我有一个带有一些文本块和按钮的应用程序,我正在尝试加载TextBlock,它隐藏整个网格,然后根据我的可见性绑定再次显示它。问题是,加载文本消失了,但主网格遮蔽了所有按钮和东西后面的网格。有没有办法正确地做到这一点?
注意:如果没有加载TextBlock,只需一个隐藏/显示我的应用程序的矩形即可正常工作。
我的代码如下所示:
<Grid Margin="2" Background="Black">
<Border BorderThickness="2" BorderBrush="Black">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="LOADING..." Visibility="{Binding DownloadingWeather, Converter={StaticResource boolToVisibilityConverter}, ConverterParameter=False}" FontSize="20" Foreground="White">
<Grid Visibility="{Binding DownloadingWeather, Converter={StaticResource boolToVisibilityConverter}, ConverterParameter=True}">
<Grid.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Gray" Offset="0.0" />
<GradientStop Color="Black" Offset="0.5" />
<GradientStop Color="Black" Offset="0.7" />
<GradientStop Color="Gray" Offset="1.0" />
</LinearGradientBrush>
</Grid.Background>
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- Some Stuff like buttons and textblocks here-->
</Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Some Stuff like buttons and textblocks here-->
</Grid>
</TextBlock>
</Border>
</Grid>
答案 0 :(得分:0)
目前Grid
是TextBlock
的一部分。由于Border
只能生一个孩子,因此您需要创建一个Grid
,同时包含您想要显示的Text
和Grid
<Border>
<Grid>
<TextBlock ... Text="LOADING..." Visibility="{Binding DownloadingWeather, Converter={StaticResource boolToVisibilityConverter}, ConverterParameter=False}"/>
<Grid Visibility="{Binding DownloadingWeather, Converter={StaticResource boolToVisibilityConverter}, ConverterParameter=True}">
<!-- Grid content -->
</Grid>
</Grid>
</Border>