2017-10-18 133 views
0

嘿所以我有一個問題讓我生氣。基本上我有一個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

這是你在找什麼?

<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

我覺得深深incongenial與利潤率做XAML佈局。我知道設計師以這種方式定位元素,但我只用設計師對我手寫的XAML進行可視化檢查。我發現使用Grid行和列,stackpanels,wrappanels和奇怪的UniformGrid會更容易和更強大。我認爲這不僅僅是我:在堆棧溢出中,我注意到邊緣驅動的佈局與那些對XAML沒有經驗的人很相關。

+1

我會永遠愛你.....非常感謝! – Seamy