2017-08-08 53 views
0

我一直在試圖創建一個listview來顯示MySQL表,但我不明白,我怎麼可以使項目被安排到列使用xaml?WPF listview根據窗口的高度顯示項目到列

這是我

My ListView

這也是我想什麼做:

Other program layout

此外,當我調整窗口的大小我想要的物品是排列成這樣的新列: Resize Window- rearrange the items

This是我的XAML代碼:

<ListView Grid.Column="1" 
      Grid.Row="1" 
      x:Name="DBTables" 
      ItemsSource="{ Binding Path=TABLENAME 
         , Source={StaticResource DBManagerResource} }" 
      MinHeight="280" 
      MinWidth="400"> 
     <ListView.ItemContainerStyle> 
      <Style TargetType="ListViewItem"> 
       <EventSetter Event="MouseDoubleClick" 
          Handler="DBTableSelect_MouseDoubleClick" /> 
      </Style> 
     </ListView.ItemContainerStyle> 
</ListView> 
+0

您的示例圖片不可用 –

+0

@MightyBadaboom你是什麼意思不可用? – Velucio

回答

1

您需要Orientation="Vertical"一個WrapPanel,禁用列表視圖垂直滾動與ScrollViewer.VerticalScrollBarVisibility="Disabled"和配置在ListView.ItemTemplate爲了在每個列表條目前顯示圖標。

<ListView MinHeight="280" MinWidth="400" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Vertical"/> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <!--Replace rectangle by your icon--> 
       <Rectangle Width="15" Height="15" Margin="5" Fill="Red" VerticalAlignment="Center"/> 
       <ContentControl Content="{Binding}" VerticalAlignment="Center"/> 
      </StackPanel> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
+0

非常感謝你!你幫了很多 – Velucio

+0

他不就是說我說的嗎? :)(他給你寫了,我會給他的) – Noctis

+0

@Noctis因爲我已經有了我的答案,如90%完成,當其他答案出現時,我覺得我的比其他答案更完整,我決定無論如何張貼它;) – grek40

0

這聽起來像你正在尋找一個類似WrapPanel什麼的。看看this article

你可能想要玩一下你的物品的風格,以便它們顯示一個圖標和一個文本,但這應該不難實現。

0

此代碼將在調整大小時處理項目。也許它會幫助你。

<ListView> 
     <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel 
        Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
        ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}" 
        MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" 
        ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" /> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <!-- Here you should add you item template, like image and text --> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
0

您需要更改ListBox的項目小組,並禁用垂直滾動條

<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled">   
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Vertical"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 
+0

這解決了調整大小的問題。 – Velucio