0
我們想使用WrapPanel顯示不同數量的按鈕(實際上Usercontrols的行爲像按鈕)。每個WrapPanel裏面都有一個ItemsControl及其項目。 WrapPanel通常不會顯示所有項目 - 如果有四個,您只會看到一個或兩個項目。行爲不一致。Silverlight WrapPanel不一致地顯示項目
有什麼我們做錯了嗎?是否有任何已知的問題使用這樣的WrapPanel?
對於XAML,這是我們的主窗口中的用戶控件:
<UserControl x:Name="ucCatalogContent" Grid.Row="2">
<local:Catalog_CategoryView />
這是類別查看標記。這有ItemsControl。它的項目是其他用戶控件,裏面還一個WrapPanel:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:local="clr-namespace:Catalog;assembly=Catalog"
x:Class="Catalog.Catalog_CategoryView"
>
<UserControl.Resources>
<DataTemplate x:Key="CategoryDT" >
<local:Category />
</DataTemplate>
</UserControl.Resources>
<ScrollViewer x:Name="scvCatalogCategoryView"
HorizontalScrollBarVisibility="Disabled">
<!-- This is the item that should be bound to the collection of categories -->
<ItemsControl x:Name="icCategories"
ItemTemplate="{StaticResource CategoryDT}"
>
<local:Category x:Name="item1" />
<local:Category x:Name="item2" />
<local:Category x:Name="item3" />
</ItemsControl>
</ScrollViewer>
,這是單獨的類別,其中使用WrapPanel:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:custom="clr-namespace:CustomControlResources;assembly=CustomControlResources"
xmlns:local="clr-namespace:Catalog;assembly=Catalog"
x:Class="Catalog.Category"
>
<UserControl.Resources>
<ItemsPanelTemplate x:Key="CategoryItemPanel">
<toolkit:WrapPanel
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
/>
</ItemsPanelTemplate>
<DataTemplate x:Key="OfferingDT" >
<local:OfferingTile x:Name="offeringTile" />
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Style="{StaticResource ContentRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<custom:BlockExpander x:Name="expCategoryExpander"
Title="access [bind me]">
<custom:BlockExpander.BlockExpanderContent>
<ItemsControl x:Name="icServiceOfferingsList"
ItemsPanel="{StaticResource CategoryItemPanel}"
ItemTemplate="{StaticResource OfferingDT}"
>
<local:OfferingTile />
<local:OfferingTile />
<local:OfferingTile />
<local:OfferingTile />
</ItemsControl>
</custom:BlockExpander.BlockExpanderContent>
</custom:BlockExpander>
</Grid>
在這個截圖中,每個擴展器頭部應該有一個標題(由藍色三角形表示),每個組應包含四個項目:
我認爲這是因爲您已將控件包裝在'ScrollViewer`(加上水平滾動條被禁用)。滾動查看器具有無限的範圍,因此需要知道父級寬度的項目可能無法正常工作。 – ChrisF 2011-01-25 22:33:25