Я пытаюсь сделать TextBlocks
свернутым (невидимым), но все еще получаю пробел / строку, даже если TextBlocks
невидимы.
Я видел во многих сообщениях, что для того, чтобы сделать TextBlock
полностью невидимым (без пробела), используется свойство видимости - Collapsed
.
Пожалуйста, найдите код, приведенный ниже, и дайте мне знать, что я делаю неправильно. Я видел очень похожие сообщения, но они не отвечают на этот вопрос.
Код Silverlight (WPF):
<phone:PhoneApplicationPage
x:Class="AndBI.MainGamePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="All is well" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,-14">
<Button Content="Go" Height="72" HorizontalAlignment="Right" Margin="0,29,0,0" Name="GO" VerticalAlignment="Top" Width="99" Click="GO_Click" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="120,29,0,0" Name="textBox1" VerticalAlignment="Top" Width="244" DataContext="{Binding}">
</TextBox>
<TextBlock Height="34" HorizontalAlignment="Left" Margin="16,50,0,0" Name="c10" Text="?" VerticalAlignment="Top" Width="112" TextWrapping="NoWrap" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="20,285,0,0" Name="b10" Text="aa" VerticalAlignment="Top" Width="112" Foreground="#FFFE6943" FontWeight="Bold" />
<TextBlock Height="30" Margin="176,285,0,0" Name="user10" Text="bb" VerticalAlignment="Top" Foreground="#FFFE6943" HorizontalAlignment="Left" Width="111" FontWeight="Bold" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="322,285,0,0" Name="c11" Text="cc" VerticalAlignment="Top" Width="105" Foreground="#FFFE6943" FontWeight="Bold" />
<Button Content="Scratch Pad" Height="72" HorizontalAlignment="Left" Margin="262,207,0,0" Name="SP" VerticalAlignment="Top" Width="194" Click="SP_Click" />
<ListBox Height="57" Background="White" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="16,144,0,0" Name="listBox1" VerticalAlignment="Top" Width="434" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Background="Red">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Text1" Margin="0,0,10,0" HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="0" />
<TextBlock Text="Text2" Margin="0,0,10,0" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" />
<TextBlock Text="Text3" Margin="0,0,10,0" HorizontalAlignment="Stretch" Grid.Column="2" Grid.Row="0" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
C # код позади:
private void CollapseAll(TextBlock tb, Boolean visible)
{
tb.Visibility = (!visible) ? Visibility.Collapsed : Visibility.Visible;
}
/**Based upon a criteria the TextBlocks are made invisible as in collapsed**/
CollapseAll(c10,false);
CollapseAll(b10,false);
CollapseAll(user10,false);
......................
......................
/**Based upon a criteria the TextBlocks are made visible**/
CollapseAll(c10,true);
CollapseAll(b10,true);
CollapseAll(user10,true);