Silverlight WrapPanel not displaying items consistently

565 views Asked by At

We would like to use the WrapPanel to display a varying number of buttons (actually Usercontrols that behave like buttons). Inside each WrapPanel is an ItemsControl with its items. Oftentimes the WrapPanel doesn’t display all the items—if there are four you only see one or two. The behavior is not consistent.

Is there something we’re doing wrong? Are there any known issues with using a WrapPanel like this?

For XAML, this is the UserControl in our main window:

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

This is the CategoryView markup. This has the ItemsControl. Its items are other UserControls with a WrapPanel inside them:

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

And this is the individual Category, where the WrapPanel is used:

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

In this screenshot, there should be a title on each expander header (by the blue triangle), and each group should contain four items: wrappanels not showing all items

1

There are 1 answers

0
dex3703 On BEST ANSWER

It turns out there was some interaction between the expander UserControl and the WrapPanel. As soon as we removed the codebehind, the wrappanel behaved normally.

We worked around this by styling the Toolkit's expander. We previously weren't using the toolkit, but since we needed the wrappanel....