隐藏在垂直屏幕上的包裹面板调整大小

时间:2017-10-18 20:11:54

标签: xaml

嘿,所以我有一个让我发疯的问题。基本上我有一个xaml元素,它有一个包裹面板和一个列表框。列表框在调整大小时没有问题,但即使我将水平对齐设置为拉伸,包装面板也不会调整大小。

有没有人就如何解决这个问题提出任何建议,因为这真的让我疯了?首先十分感谢。

 <UserControl x:Class="citeright_word.SearchItemsPanel"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"         
         xmlns:local="clr-namespace:citeright_word"
         xmlns:iconPacks1="http://metro.mahapps.com/winfx/xaml/iconpacks"

         mc:Ignorable="d" 
         d:DesignHeight="562.5" d:DesignWidth="300">
<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Resources/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>



    <Label x:Name="label" Content="Search:" Margin="5,0,0,0" 
  VerticalAlignment="Top" FontSize="16" FontWeight="Bold"/>
    <WrapPanel  HorizontalAlignment="Stretch" Width="auto"  
  Margin="5,30,5,506.4">
        <Button  Click="refreshItems" Background="#FFF7F7F7" 
  VerticalAlignment="Top">
            <iconPacks1:PackIconMaterial  Kind="Refresh" MaxHeight="12" 
  MaxWidth="12"/>
        </Button>
        <TextBox   x:Name="textBox" controls:TextBoxHelper.Watermark="Search 
 Items" controls:TextBoxHelper.ClearTextButton="True" 
 VerticalAlignment="Top" 
 KeyDown="textBox_KeyDown"  />
    </WrapPanel>
    <ListBox x:Name="listBox" Margin="5,63,5,5" 
 HorizontalContentAlignment="Stretch" 
 ScrollViewer.HorizontalScrollBarVisibility="Disabled">

    </ListBox>
</Grid>
  </UserControl>

enter image description here

1 个答案:

答案 0 :(得分:1)

这是你要找的吗?

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Label 
        x:Name="label" 
        Grid.Row="0"
        Content="Search:" 
        Margin="5,0,0,0" 
        VerticalAlignment="Top" 
        FontSize="16" 
        FontWeight="Bold"
        />
    <Grid 
        Margin="5"
        Grid.Row="1"
        >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Button  
            Grid.Column="0"
            Click="refreshItems" 
            Background="#FFF7F7F7" 
            VerticalAlignment="Top"
            >
            <iconPacks1:PackIconMaterial 
                Kind="Refresh" 
                MaxHeight="12" 
                MaxWidth="12" />
        </Button>
        <TextBox   
            Grid.Column="1"
            Margin="2,0,0,0"
            x:Name="textBox" 
            VerticalAlignment="Top" 
            KeyDown="textBox_KeyDown"
            controls:TextBoxHelper.Watermark="Search Items" 
            controls:TextBoxHelper.ClearTextButton="True" 
            />
    </Grid>
    <ListBox 
        x:Name="listBox" 
        Grid.Row="2"
        Margin="5"
        HorizontalContentAlignment="Stretch" 
        ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBoxItem>DSG Global Inc (re)</ListBoxItem>
        <ListBoxItem>Law Society of New Brunswick v. Aucoin</ListBoxItem>
    </ListBox>
</Grid>

我做了一些替换测试,因为我没有你的图标或文本框行为或列表框中的内容。

enter image description here

我发现使用边距进行XAML布局非常不合适。我知道设计师以这种方式定位元素,但我只使用设计器对我手工编写的XAML进行目视检查。我发现使用Grid行和列,stackpanels,wrappanels和奇怪的UniformGrid会更加容易和强大。我认为这不仅仅是我:在堆栈溢出时,我注意到保证金驱动的布局与那些缺乏XAML经验的人非常相关。