2012-07-21 43 views
15

我想改變的ListView項目(?也許我應該使用其他瀏覽元)之間的間距之間的空間代碼如下所示:Windows8的ListView和項目

<ListView SelectionMode="None" HorizontalContentAlignment="Left" > 
     <ListView.Items> 
      <TextBlock Text="Item 1" /> 
      <TextBlock Text="Item 2" /> 
      <TextBlock Text="Item 3" /> 
      <TextBlock Text="Item 4" /> 
     </ListView.Items> 
     <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapGrid Orientation="Horizontal" HorizontalChildrenAlignment="left"/> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 
    </ListView> 

我想模仿儘可能正常stackpanel(可以包裝元素)。目前空間(水平空間)之間的項目太大了。我剛纔的問題 - >Windows 8 WrapPanel

在此先感謝

回答

25

您需要對默認模板進行更改。通過選擇ListViewItem的(測試的代碼,並要工作)

  <ListView> 
     <ListView.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapGrid Orientation="Horizontal" HorizontalChildrenAlignment="left"/> 
       </ItemsPanelTemplate> 
      </ListView.ItemsPanel> 
     <ListView.ItemContainerStyle> 
       <Style TargetType="ListViewItem"> 
        <Setter Property="Padding" Value="0"/> 
        <Setter Property="Margin" Value="0"/> 
       </Style> 
      </ListView.ItemContainerStyle> 
      <ListViewItem> 
       <TextBlock Foreground="Wheat">hej</TextBlock> 
      </ListViewItem> 
      <ListViewItem> 
       <TextBlock Foreground="Wheat">hej</TextBlock> 
      </ListViewItem> 
     </ListView> 

更多的控制使整個默認模板的副本:如果你只是想進行簡單的更改,如填充和利潤,那麼你可以這樣做在設計師和右鍵單擊。選擇編輯模板,編輯副本。這將生成默認模板,您可以在那裏進行更改。你可以爲listviewcontainer做同樣的事情。你也可以使用Blend來做到這一點。

I've added a description and images here (how you can edit a default template)

讓我知道如何去,如果您有更多問題!祝你好運!

編輯:下面,他仍然有問題,通過調整他發佈了一個代碼,並回答這裏的一些其他屬性 - 解決它提到

MemeDeveloper,一定要看一看。

+0

感謝您的幫助:)還有一個問題。我幾乎可以確定它應該以他的方式完成,但是我找不到可以編輯這些樣式的工具。例如,我如何在Blend中做到這一點? – 2012-07-22 12:08:12

+2

我已經發布了一篇博客文章,其中包含了關於如何在VS中完成它的描述和圖像,或者混合:)希望它有幫助!不要猶豫,問更多的問題等鏈接:http://www.irisclasson.com/2012/07/22/example-winrtmetro-app-how-to-edit-default-template-in-visual-studio- 2012-and-blend/ – 2012-07-22 16:01:52

+0

哇,太棒了!非常感謝你:) – 2012-07-22 20:02:55

2

你需要編輯ListBox.ItemContainerTemplate財產。混合或VS視覺設計師幫助提取它進行修改。

+0

...是的,特別是在它內ListViewItemPresenter的ContentMargin和Padding屬性 – MemeDeveloper 2014-05-23 06:35:16

16

據我所知(windows8.1 XAML商店應用),設置完成後這兩個零

<ListView.ItemContainerStyle> 
       <Style TargetType="ListViewItem"> 
        <Setter Property="Padding" Value="0"/> 
        <Setter Property="Margin" Value="0"/> 

我仍然有令人沮喪的差距似乎我無法擺脫的。

使用負利潤率在這裏可能會爲你做,但是......它的哈克,很難的工作,並不會總是導致預期的結果

拉我的頭髮後,我發現這個問題已解決與這些傢伙,即

ContentMargin = 「0」 填充= 「0」

ListViewItemPresenter如下:

 <ListView.ItemContainerStyle> 
      <Style TargetType="ListViewItem"> 
       <Setter Property="Padding" Value="0" /> 
       <Setter Property="Margin" Value="0" /> 
       <Setter Property="BorderThickness" Value="0" /> 
       <Setter Property="VerticalContentAlignment" Value="Top" /> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="ListViewItem"> 
          <ListViewItemPresenter ContentMargin="0" Padding="0" /> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </ListView.ItemContainerStyle> 

希望可以節省有人從他們的鍵盤上反覆砸其頭部別的;)

+1

你保存了我的一天,隊友:-) :-)。我很多天以來一直在努力尋找這一點。 – 2015-04-15 12:19:07

+0

我已經花了幾個小時,如果我沒有發現這個,我會花幾天時間! – 2018-02-26 07:11:16

+0

我仍然需要負面的ContentMargin來進一步減少邊距。 – 2018-02-26 07:42:14

1

解決方案eleminating在GridView的項目利潤率爲8.1的Windows Store應用。受上述ListView解決方案的啓發。

<GridView.ItemContainerStyle> 
<Style TargetType="GridViewItem"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="GridViewItem"> 
       <GridViewItemPresenter ContentMargin="0" Padding="0"/> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
</GridView.ItemContainerStyle> 
7

我認爲正確的ItemContainerStyle屬性在這裏修改爲了minHeight,沒有保證金或填充。