2015-08-18 114 views
0

SOF部落Windows手機8.1流動容器,動態按鈕

我有一個流容器,其中我可以倒的動態創建XAML按鈕不確定數目的標識的請求。所述按鈕應該儘可能地包裝文本(我認爲我有一個這樣的模板)。但按鈕應該像gridview一樣包裝,但像堆棧面板一樣運行。有誰知道一個容器可以讓我完成圖像所描繪的內容?

目前,對於下面的現有圖像,我使用的是gridview,但gridview設置了特定的寬度但流量不均勻。一個堆棧面板具有理想的端對端風格,但不會包裝。那麼,有什麼想法?

Auto wrapping flow container

回答

2

有所謂由Greg斯托爾作出的UniversalWrapPanel。所以,這是我將要採取的方向。然而,現在我已經有了最後一點需要解決的問題了。如何獲得綁定數據以尊重父容器的內容包裝能力,而不是將其堆疊在垂直列中。

下面的XAML給我下面的圖像結果,這是不是我想要的。靜態添加的按鈕對UniversalWrapPanel工作得很好。但試圖獲得一個綁定和ItemsSource的工作,好吧,這是目前超出我的。

enter image description here

<support:UniversalWrapPanel Orientation="Horizontal" Background="White"> 
    <ItemsControl x:Name="GridViewRecipients" ItemsSource="{Binding}"> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Button Style="{StaticResource ButtonLozengeStyle}" Content="{Binding FullName}"/> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 
</support:UniversalWrapPanel> 

好了,更多的搜索,我發現這一點:

http://www.visuallylocated.com/post/2015/02/20/Creating-a-WrapPanel-for-your-Windows-Runtime-apps.aspx

,因此這裏是ItemsControl的範圍內引用UniversalWrapPanel正確的方法:

<ItemsControl x:Name="GridViewRecipients" ItemsSource="{Binding}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <support:UniversalWrapPanel Orientation="Horizontal" Background="DodgerBlue"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Button Style="{StaticResource ButtonLozengeStyle}" Content="{Binding FullName}"/> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

結果爲:

enter image description here