PopupGallery width incorrect on first open

Ribbon for WPF Forum

Posted 8 years ago by Eric P
Version: 15.1.0624
Avatar

I am binding the ItemsSource of the Ribbon PopupGallery to an ObservableCollectoin in my ViewModel that is populated with items from an async Task. This is the XAML I have so far.

<ribbon:PopupButton Label="Basemaps" ImageSourceLarge="", ImageSourceSmall="" PopupResizeMode="Both">
  <ribbon:PopupGallery InitialColumnCount="3" VerticalScrollBarVisibility="Hidden" ItemsSource="{Binding BasemapItems}">
    <ribbon:PopupGallery.ItemTemplate>
      <DataTemplate>
        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
          <Image Source="{Binding ThumbnailUrl}" Stretch="None" />
          <TextBlock Text={Binding Name}" TextAlignment="Center" />
        </StackPanel>
      </DataTemplate>
    </ribbon:PopupGallery.ItemTemplate>
  </ribbon:PopupGallery>
</ribbon:PopupButton>

When I click the PopupButton, the first time to open the gallery items, they are all drawn in one single vertical column and the images are cut off because the column is to narrow. If I click it the second time the width of the PopupGallery seems to have updated and I can see the items correctly using three columns. I think that since the Image Source is a Url there might be a timing issue when the PopupGallery calculates its width, which seems to be before it knows how wide the image is. Its like its trying to calculate the width of the PopupGallery before it knows the width of the images because they have not been downloaded yet. I know that each of these items are 200px wide so I change the XAML to the following.

<StackPanel Orientation="Vertical" VerticalAlignment="Center" Width=200">

That works better but I wanted to make sure there was not a more dynamic approch incase the items with changes in the future.

Thanks

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Eric,

That's right, it will try and measure the first item and use that as the size for the remaining.  By setting the Width as you did, that will work great.  The gallery item chrome will measure around the width you set.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.