2014-09-12 32 views
0

我是Windows Phone應用程序開發的新手。我正在顯示listview中的一些項目的列表。它對我來說非常完美,但是當問題出現在設計上的時候。我如何設置我的列表視圖的動態寬度。即如果我以不同的分辨率&模式打開我的應用程序,它應該是全寬度。Windows Phone應用程序8.1中的動態列表視圖佈局

如果我給定我的列表視圖的寬度,它不是正確顯示在所有決議&模式。我知道*大小,但當我給*大小,它給我錯誤的App.g.i.cs文件。在此聲明

if(global :: System.Diagnostics.Debugger.IsAttached)global :: System.Diagnostics.Debugger.Break();

請指教。

+0

你把*放在哪裏? 「寬度」或「長度」僅支持Numbers。 ListView通常應該在你的Page-> Grid中,並且應該自動縮放。 – malte 2014-09-12 10:59:35

+0

是的,它在Page-> Grid中。我在Listview中放置了多個StackPanel。我給*我的StackPanel寬度 – user3683028 2014-09-12 11:02:09

+0

@malte你能幫我這個嗎?這很緊急。 – user3683028 2014-09-12 11:22:08

回答

2

爲了讓ListView的項目取足可用寬度,設置項容器樣式如下:

<ListView.ItemContainerStyle> 
    <Style TargetType="ListViewItem"> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    </Style> 
</ListView.ItemContainerStyle> 

佈局列表視圖中的項目,如您在評論願意,你可以使用一個網格:

<ListView.ItemTemplate> 
    <DataTemplate> 
    <Grid HorizontalAlignment="Stretch" > 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="20" /> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="20" /> 
     </Grid.ColumnDefinitions> 
     ... put your controls in the appropriate grid cells 
    </Grid> 
    </DataTemplate> 
</ListView.ItemTemplate> 
+0

感謝您的建議。基本上,我需要格式化我的列表視圖3列,所有不同的寬度。我的第一個和最後一列寬度已修復。中柱寬度應根據可用空間進行調整。你能提供這方面的建議嗎?非常感謝你。 – user3683028 2014-09-12 11:32:15

+0

@ user3683028我在我的回答中添加了一個例子 – Jogy 2014-09-12 11:36:13

+0

完美的作品。非常感謝。 – user3683028 2014-09-12 11:41:39

相關問題