2016-01-11 55 views
0

我想要以某種方式顯示列表框中的圖像。現在可能在具有多行的列表框中顯示圖像

列表框:

enter image description here

如何,我想:

enter image description here

正如你可以看到我想要的滾動條將下降一側,那裏是多列和行取決於列表框的大小。

+0

ListView可以幫助你 –

+0

@不幸我現在來看看這個,謝謝你回到我身邊。 –

回答

1

定義WrapPanelListBoxItemsPanel

  <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapPanel ></WrapPanel> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 

不要忘記設置WidthMaxWidth到畫布面板。一旦達到最大寬度,它將開始將內容放置在新線上...

+0

這似乎工作,但我沒有得到任何滾動條? –

0

使用寬度設置爲值的WrapPanel。對於例如運行下面的代碼:

<Window x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:WpfApplication1" 
    Title="MainWindow" Height="350" Width="525" > 
<Window.DataContext> 
    <local:ParentViewModel /> 
</Window.DataContext> 

<ListBox Height="auto" ItemsSource="{Binding MyList,Mode=TwoWay}"> 
    <ListBox.Style> 
     <Style TargetType="{x:Type ListBox}"> 
      <Setter Property="ItemTemplate" > 
       <Setter.Value> 
        <DataTemplate> 
         <Button Content="{Binding}" Padding="15,5" Margin="100,40,0,0" 
           Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}},Path=DataContext.RemoveButtonCommand}" 
           CommandParameter="{Binding}" 
           /> 
        </DataTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </ListBox.Style> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=ActualWidth}" 
         >      
      </WrapPanel> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 

您將獲得垂直和水平滾動條。都根據窗口的高度和寬度用listbox中的元素進行調整。 (請綁定你自己的列表框源代碼)

相關問題