GalleryItems generation with MVVM + Gallery bug

Aug 26, 2011 at 9:02 AM

Hi,

First of all, thank you so much for this truly awesome control, I've never made nice applications that easily.

 

However, I'm running into a bunch of problems last times and wonder if you could help me.

So, I have two problems listed so far (well, the first problem is actually composed by two problems - heh), all regarding the Gallery / Gallery Item

 

First problem: MVVM item generation


Situation: I have a SplitButton, and I want its content to be generated dynamically using MVVM (it iterates in enum values and displays one item for each value)

Problem: I'm working with MVVM, thus I use a databound ItemsSource to generate its content. I want to use a Gallery in the SplitButton popup (especially for using the nice GroupBy function!).

I end up with two problems here:

  • The GroupBy function just does not work. It displays one group tag, "Undefined", and put all stuff inside
  • Clicking on the GalleryItem (which should fire a Command) just does not work. I had a NullReference in GalleryItem.cs, on click, saying that the selector parent was null. I try/catched it, and now it works, but when I click on an item, it'll always stay selected

For the record, I've set Gallery's ItemSource property and an ItemTemplate (which is working quite well, at least, I get the exact visual result I wanted)

I've tried two different ways, having a very different behavior:

The first one gives me a nice visual style, but no group filtering (the Tag is correctly initialized in Converter) and clicking gets me into trouble:

<Fluent:Gallery ItemsSource="{Binding DockableTabTypesList, Mode=OneTime}"
                        GroupBy="Tag"
                        Orientation="Vertical"
                        ScrollViewer.CanContentScroll="False"
                       
                        >
            <Fluent:Gallery.ItemTemplate>
                <DataTemplate>
                    <Fluent:GalleryItem Tag="{Binding Converter={StaticResource TitleConverter}}"
                            Command="{Binding DataContext.AddTabCommand,
                                                RelativeSource={RelativeSource FindAncestor,
                                                                AncestorType={x:Type Fluent:RibbonGroupBox}}}"
                              CommandParameter="{Binding}">
                        <Fluent:GalleryItem.Content>
                            <DockPanel LastChildFill="True">
                                <Image Source="{Binding Converter={StaticResource IconConverter}}"
                               DockPanel.Dock="Left" Height="35" Width="35" />
                                <StackPanel Margin="5" Orientation="Vertical" Width="170">
                                    <TextBlock Text="{Binding}" FontWeight="Bold"  />
                                    <TextBlock Text="{Binding Converter={StaticResource DescriptionConverter}}"
                                               TextWrapping="Wrap"/>
                                </StackPanel>
                            </DockPanel>
                        </Fluent:GalleryItem.Content>
                    </Fluent:GalleryItem>
                </DataTemplate>
            </Fluent:Gallery.ItemTemplate>
        </Fluent:Gallery>

The second one... just doesn't do anythin (keeps generating me MenuItems just as if I had set SplitButton's ItemSource) :

<Fluent:SplitButton Header="Display"
                        LargeIcon="{StaticResource ContentIcon}" Fluent:KeyTip.Keys="D"
                        ItemsSource="{Binding DockableTabTypesList, Mode=OneTime}"
                        >
        <Fluent:SplitButton.ItemsPanel>
            <ItemsPanelTemplate>
                <Fluent:Gallery Orientation="Vertical" GroupBy="Tag" />
            </ItemsPanelTemplate>
        </Fluent:SplitButton.ItemsPanel>
        <Fluent:SplitButton.ItemTemplate>
            <DataTemplate>
                <Fluent:GalleryItem Tag="{Binding Converter={StaticResource TitleConverter}}"
                            Command="{Binding DataContext.AddTabCommand,
                                                RelativeSource={RelativeSource FindAncestor,
                                                                AncestorType={x:Type Fluent:RibbonGroupBox}}}"
                              CommandParameter="{Binding}">
                    <Fluent:GalleryItem.Content>
                        <DockPanel LastChildFill="True">
                            <Image Source="{Binding Converter={StaticResource IconConverter}}"
                               DockPanel.Dock="Left" Height="35" Width="35" />
                            <StackPanel Margin="5" Orientation="Vertical" Width="170">
                                <TextBlock Text="{Binding}" FontWeight="Bold"  />
                                <TextBlock Text="{Binding Converter={StaticResource DescriptionConverter}}"
                                               TextWrapping="Wrap"/>
                            </StackPanel>
                        </DockPanel>
                    </Fluent:GalleryItem.Content>
                </Fluent:GalleryItem>
            </DataTemplate>
        </Fluent:SplitButton.ItemTemplate>

 

So... Any ideas here? I guess the problem is maybe Gallery does a prior filtering by tag and then generates visual styles, which wouldn't be compatible with my MVVM approach including dynamic tag generation...

 

Second problem

Okay, the second one is... Pretty disturbing. I'd even say that it is a Ribbon bug and not a problem: Once the gallery is generated, if I happen to scroll with my mouse, it won't scroll in the gallery in any way. Actually, it'll rather scroll in the ribbon and change the tab.

Problem here? If I happen to change the tab and come back to the previous one, clicking on the SplitButton won't display any popup again. It'll just "activate" the button and block all the Ribbon. Any insights on this one?

 

 

Thanks again!

Feb 10, 2014 at 5:42 PM
I am having the same issues. Any new feedback or developments with this?
Developer
Feb 10, 2014 at 11:04 PM
The sad reality is this:
I seem to be the only one commiting to this project in a constant manner...
As i don't use/need the gallery and suspect there is much work involved fixing it, at least i won't fix it.

But feel free to fix it and send me a pull request. ;-)