0

我们想使用 WrapPanel 来显示不同数量的按钮(实际上是行为类似于按钮的用户控件)。每个 WrapPanel 内部都有一个 ItemsControl 及其项目。WrapPanel 通常不会显示所有项目——如果有四个,您只会看到一两个。行为不一致。

我们做错了什么吗?使用这样的 WrapPanel 是否有任何已知问题?

对于 XAML,这是我们主窗口中的 UserControl:

<UserControl x:Name="ucCatalogContent" Grid.Row="2">
   <local:Catalog_CategoryView />

这是 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>

在此屏幕截图中,每个扩展器标题(蓝色三角形)应该有一个标题,每个组应该包含四个项目: 包装板未显示所有项目

4

1 回答 1

0

事实证明,扩展器 UserControl 和 WrapPanel 之间存在一些交互。一旦我们删除了代码隐藏,包装面板就会正常运行。

我们通过设置 Toolkit 扩展器的样式来解决这个问题。我们以前没有使用工具包,但因为我们需要包装板......

于 2011-01-27T02:27:18.563 回答