2016-01-11 37 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中的元素进行调整。 (请绑定你自己的列表框源代码)

相关问题