在WP8中隐藏下拉菜单

时间:2015-03-30 22:57:34

标签: c# windows-phone-7 windows-phone-8 windows-phone-8.1

我正在尝试隐藏wp8.it工作正常的下拉列表,但是显示空间。我如何删除此空间并根据显示/隐藏列表使按钮组合向上和向下

enter image description here

是否有任何其他隐藏文本块的方法。因为System.Windows.Visibility.Collapsed不适用于Textblock。

  <Grid HorizontalAlignment="Left" Height="661" Margin="0,130,0,0" VerticalAlignment="Top" Width="440">
                            <Grid>
                                <TextBox HorizontalAlignment="Left" Height="65" Margin="-3,10,0,0" TextWrapping="Wrap"   VerticalAlignment="Top" Width="433" GotFocus="WatermarkTB_GotFocus" Foreground="Gray"
          LostFocus="WatermarkTB_LostFocus" x:Name="txtsearch" Text="Search" BorderBrush="LightGray"/>

                                <toolkit:ListPicker x:Name="lstLocations" Foreground="Black"   
                         BorderThickness="0.2" SelectionMode="Single" SelectionChanged="Locations_SelectionChanged"
                        VerticalAlignment="Bottom" Margin="10,0,23,500"   BorderBrush="Black" Height="88"  >
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel >
                                                <TextBlock Text="{Binding name}"  Foreground="Black" FontSize="18"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                    <toolkit:ListPicker.FullModeItemTemplate>
                                        <DataTemplate>
                                            <StackPanel>
                                                <TextBlock Text="{Binding name}"                                  
                                       FontSize="28"
                                                       Foreground="White"
                                                                                              />
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.FullModeItemTemplate>
                                </toolkit:ListPicker>

                                <toolkit:ListPicker x:Name="lstSubLocations" Foreground="Black"   
                         BorderThickness="0.2" SelectionMode="Single" SelectionChanged="lstSubLocations2_SelectionChanged"
                        VerticalAlignment="Bottom" Margin="10,0,23,460" ExpansionMode="FullScreenOnly" Visibility="Collapsed"  BorderBrush="Black" Height="64"  >
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel >
                                                <TextBlock Text="{Binding name}"  Foreground="Black" FontSize="18"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                    <toolkit:ListPicker.FullModeItemTemplate>
                                        <DataTemplate>
                                            <StackPanel>
                                                <TextBlock Text="{Binding name}"                                  
                                       FontSize="28"
                                                       Foreground="White"
                                                                                              />
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.FullModeItemTemplate>
                                </toolkit:ListPicker>

                                <toolkit:ListPicker x:Name="lstSubLocations2" Foreground="Black"   
                         BorderThickness="0.2" SelectionMode="Single" 
                        VerticalAlignment="Bottom" Margin="10,0,23,390" ExpansionMode="FullScreenOnly" BorderBrush="Black" Height="64" Visibility="Collapsed"  >
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel >
                                                <TextBlock Text="{Binding name}"  Foreground="Black" FontSize="18" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                    <toolkit:ListPicker.FullModeItemTemplate>
                                        <DataTemplate>
                                            <StackPanel>
                                                <TextBlock Text="{Binding name}"                                  
                                       FontSize="28"
                                                       Foreground="White"
                                                                                              />
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:ListPicker.FullModeItemTemplate>
                                </toolkit:ListPicker>
                            </Grid>
                            <Grid Margin="0 170 0 0">
                                <Button Content="Search Jobs" x:Name="Serachjob" FontSize="20" Foreground="White" HorizontalAlignment="Left" Margin="0,172,0,0" VerticalAlignment="Top" Width="204" Grid.ColumnSpan="2" BorderThickness="0" Click="Serachjob_Click">
                                    <Button.Background>
                                        <ImageBrush Stretch="Fill"  ImageSource="/Image/jobseeker.png"/>
                                    </Button.Background>

                                </Button>
                                <Button Content="Advanced Search" x:Name="Advanced_Search" Foreground="White" FontSize="20"  HorizontalAlignment="Left" Margin="202,172,0,0" VerticalAlignment="Top" Width="215" BorderThickness="0" Click="Advanced_Search_Click">
                                    <Button.Background>
                                        <ImageBrush Stretch="Fill" ImageSource="/Image/loginEmp.png"/>
                                    </Button.Background>
                                </Button>
                                <Button Content="Post Resumes" x:Name="Post_Resume" FontSize="20" Foreground="White" HorizontalAlignment="Left" Margin="0,222,0,0" VerticalAlignment="Top" Width="204" Grid.ColumnSpan="2" BorderThickness="0" Click="Post_Resume_Click">
                                    <Button.Background>
                                        <ImageBrush Stretch="Fill"  ImageSource="/Image/jobseeker.png"/>
                                    </Button.Background>

                                </Button>
                                <Button Content="Browse Jobs" x:Name="Browse_Jobs" Foreground="White" FontSize="20"  HorizontalAlignment="Left" Margin="202,222,0,0" VerticalAlignment="Top" Width="215" BorderThickness="0" Click="Browse_Jobs_Click">
                                    <Button.Background>
                                        <ImageBrush Stretch="Fill" ImageSource="/Image/loginEmp.png"/>
                                    </Button.Background>
                                </Button>

                            </Grid>


                        </Grid>

1 个答案:

答案 0 :(得分:1)

问题是您在该网格上使用Margin。特别是这个,

 <Grid Margin="0 170 0 0">

如果您想根据内容自动调整大小,请尝试使用RowDefinition设置为Auto的网格,并将控件放在各行中。

或者您可以使用StackPanel来控制您的控件。您还可以在StackPanel内使用Grid

这样的事情:

<Grid x:Name="LayoutRoot" Background="#FFAAAAAA">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Background="#FFD8CCFF">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="Dogecoin WP8" Foreground="Black" Margin="12,0"/>
        <TextBlock x:Name="StatusLabel" Grid.Column="1" Text="" HorizontalAlignment="Right" Padding="0,0,12,0" Foreground="Black"/>
    </Grid>

    <StackPanel Grid.Row="1" Margin="0,5,0,0">
    <!-- TODO: your controls here -->
    </StackPanel>
</Grid>

然后展开或隐藏可折叠ListPicker / StackPanel内的Grid应导致此

enter image description here

了解ListPicker展开后它是如何推动所有内容的?

作为旁注,当你想要一些被动的东西时,要小心使用Margins

相关问题