2013-10-16 30 views
2

我需要並排顯示多個列表框,但是我不知道在任何時候會有多少個列表框。我曾經做過這個網站,但已經決定轉向桌面解決方案,所以需要從網站上重新創建佈局。WPF窗體的佈局 - 水平列表框

這是我想擁有的一切: enter image description here

這是我在用WPF enter image description here

這是我目前XAML文件分鐘。

<Grid> 
    <StackPanel Height="auto" Width="auto"> 
     <StackPanel Orientation="Horizontal"> 
      <WrapPanel Orientation="Horizontal"> 
       <ListBox ItemsSource="{Binding BoardMarker.Events}" Height="auto" Width="auto" Padding="-6,-3,0,-5"> 
        <ListBox.ItemTemplate> 
         <HierarchicalDataTemplate> 
          <StackPanel> 
           <Label Foreground="White" FontWeight="Bold" Content="{Binding Name}" > 
            <Label.Background> 
             <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
              <GradientStop Color="Black" Offset="0"/> 
              <GradientStop Color="#FF7A7A7A" Offset="1"/> 
             </LinearGradientBrush> 
            </Label.Background> 
           </Label> 
           <ListBox ItemsSource="{Binding Markets}" Padding="-6,-5,-6,-10"> 
            <ListBox.ItemTemplate> 
             <HierarchicalDataTemplate> 
              <StackPanel Width="auto"> 
               <Grid MinWidth="120" Background="DodgerBlue"> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition Width="55*"/> 
                 <ColumnDefinition Width="45*"/> 
                </Grid.ColumnDefinitions> 
                <Label Content="{Binding Name}" HorizontalAlignment="left" FontSize="8" Padding="0,2" Foreground="White" FontWeight="Bold"/> 
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Background="DodgerBlue" Margin="0,0,2,0" Grid.Column="1"> 
                 <Label Content="{Binding NumberOfRunners}" FontSize="7" ClipToBounds="False" SnapsToDevicePixels="True" Padding="0,2" Foreground="White" FontWeight="Bold"/> 
                 <Label HorizontalAlignment="Right" Content="Run - " FontSize="7" Padding="0,2" Foreground="White" FontWeight="Bold"/> 
                 <Label Content="{Binding NumberOfNonRunners}" FontSize="7" Padding="0,2" Foreground="White" FontWeight="Bold"/> 
                 <Label Content="NR" FontSize="7" Padding="0,2" Foreground="White" FontWeight="Bold"/> 
                </StackPanel> 
               </Grid> 

               <ListBox ItemsSource="{Binding Selections}" Width="auto" Padding="-2"> 
                <ListBox.ItemTemplate> 
                 <HierarchicalDataTemplate> 
                  <Grid Width="auto" MinWidth="120" Margin="-2"> 
                   <Grid.ColumnDefinitions> 
                    <ColumnDefinition Width="10*"/> 
                    <ColumnDefinition Width="70*"/> 
                    <ColumnDefinition Width="15*"/> 
                    <ColumnDefinition Width="15*"/> 
                   </Grid.ColumnDefinitions> 
                   <Label Content="{Binding Number}" FontSize="7" Padding="2"/> 
                   <Label Content="{Binding Name}" FontSize="7" Padding="2" Grid.Column="1" /> 
                   <Label Content="{Binding CurrentPrice}" FontSize="7" Padding="2" HorizontalAlignment="Right" Grid.Column="2"/> 
                   <Label Foreground="DarkGray" Content="{Binding OpeningPrice}" FontSize="7" Padding="2" HorizontalAlignment="Right" Grid.Column="3"/> 
                  </Grid> 
                 </HierarchicalDataTemplate> 
                </ListBox.ItemTemplate> 
               </ListBox> 
              </StackPanel> 
             </HierarchicalDataTemplate> 
            </ListBox.ItemTemplate> 
           </ListBox> 
          </StackPanel> 
         </HierarchicalDataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
      </WrapPanel> 
     </StackPanel> 
    </StackPanel> 
</Grid> 

回答

0

你的內層StackPanel的默認方向是Vertical。將其設置爲水平。如果你希望它們運行左 - >右,然後到下一行,你可能想考慮一個水平方向的WrapPanel。