不显示字段

时间:2013-12-04 09:57:24

标签: c# xaml windows-phone-8

不要显示"主持人"和" port"领域。请帮助找到错误。

<!--ContentPanel – поместите здесь дополнительное содержимое-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,14,0">
        <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.ConnectionName, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="TitleServer" HorizontalAlignment="Left" Height="72" Margin="0,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
        <TextBlock HorizontalAlignment="Left" Margin="11,109,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Host, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <StackPanel Margin="0,130,10,436" Orientation="Horizontal">
            <TextBox HorizontalAlignment="Left" x:Name="Host" TextWrapping="Wrap" Height="72" Width="345"/>
            <TextBox HorizontalAlignment="Left" x:Name="Port" TextWrapping="Wrap" Height="72" Width="100" InputScope="Number"/>
        </StackPanel>
        <TextBlock HorizontalAlignment="Left" Margin="11,210,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Login, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="Login" HorizontalAlignment="Left" Height="72" Margin="0,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
        <TextBlock HorizontalAlignment="Left" Margin="11,314,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Password, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="Password" HorizontalAlignment="Left" Height="72" Margin="0,340,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
    </Grid>

2 个答案:

答案 0 :(得分:1)

将StackPanel的visibility-property设置为CollapsedHidden。或者,如果您愿意,可以单独在每个TextBox控件上设置此属性。

<StackPanel Visibility="Collpased" Margin="0,130,10,436" Orientation="Horizontal">
    <TextBox HorizontalAlignment="Left" x:Name="Host" TextWrapping="Wrap" Height="72" Width="345"/>
    <TextBox HorizontalAlignment="Left" x:Name="Port" TextWrapping="Wrap" Height="72" Width="100" InputScope="Number"/>
</StackPanel>

有关MSDN属性的更多信息:

  • 可见:显示元素。
  • 隐藏:不显示元素,但为布局中的元素保留空间。
  • 折叠:不显示元素,也不要在布局中为其预留空间。

答案 1 :(得分:1)

试试这个

  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,14,0">
        <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.ConnectionName, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="TitleServer" HorizontalAlignment="Left" Height="72" Margin="0,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
        <TextBlock HorizontalAlignment="Left" Margin="11,109,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Host, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <StackPanel Margin="0,130,10,0" Orientation="Horizontal" VerticalAlignment="Top">
            <TextBox HorizontalAlignment="Left" x:Name="Host" TextWrapping="Wrap" Height="72" Width="345"/>
            <TextBox HorizontalAlignment="Left" x:Name="Port" TextWrapping="Wrap" Height="72" Width="100" InputScope="Number"/>
        </StackPanel>
        <TextBlock HorizontalAlignment="Left" Margin="11,210,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Login, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="Login" HorizontalAlignment="Left" Height="72" Margin="0,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
        <TextBlock HorizontalAlignment="Left" Margin="11,314,0,0" TextWrapping="Wrap" Text="{Binding LocalizedResources.Password, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top"/>
        <TextBox x:Name="Password" HorizontalAlignment="Left" Height="72" Margin="0,340,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="446"/>
    </Grid>

问题在于StackPanel的保证金属性。请注意,我也添加了 VerticalAlignment 属性。

  

实际上你只需要使用StackPanel作为ContentPanel而不是   使用Grid,这样您就可以将控件放在一个订单下面   没有任何保证金。这将更容易