2015-03-30 79 views
0

我試圖隱藏wp8.it的做工精細下拉列表中,但是顯示space.How我可以刪除這個空間,使向上和downwords基於顯示/隱藏列表隱藏下拉在WP8

按鈕組enter image description here

是否有其他方法來隱藏textblock.because System.Windows.Visibility.Collapsed不工作文本塊。

<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> 
+0

發佈您的XAML代碼或更加描述您的問題。如果你在'StackPanel'中有你的控件,那麼使用Collapsed會導致所有東西都被推上去。基本上,如果控制不存在於Visual Tree中。 – 2015-03-31 00:05:10

+0

@ChubosaurusSoftware thnks for reply.I已更新問題與我的XAML文件 – hii 2015-03-31 06:54:18

回答

1

問題是,您在該網格上使用的是Margin。具體來說這一個,

<Grid Margin="0 170 0 0"> 

如果要根據內容自動調整大小嚐試使用網格RowDefinition設置爲Auto並把你的控件在各個行。

或者您可以使用StackPanel來放置您的控件。您也可以在Grid內使用StackPanel

事情是這樣的:

<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

+0

我真的很感激你的迴應,並教我如何使用margin.But我的主要問題是。我使用級聯下拉式。如果我選​​擇像印度的國家,然後自動城市下拉菜單出現.on c#編碼我只是隱藏城市下拉,當我隱藏它也獲得空間。這就是爲什麼這個按鈕顯示belolw.how我可以處理這.. ..? – hii 2015-03-31 19:11:53

+0

@hii是的,我知道你在說什麼hii。你使用兩個'ListPicker's。你想要做的是擺脫那個邊距,然後使用'StackPanel'。在'StackPanel'裏面包含你的兩個'ListPicker's然後你的一組按鈕。然後隱藏任何ListPicker將導致項目被推高(無空格)。 – 2015-03-31 19:28:35