Ribbon Gallery, Binding & Category

Ribbon for WPF Forum

Posted 10 years ago by John Kelly
Avatar
Hi,

I've bound a gallery to an item source but i'm unable to figure out how to set the PopupGallery.Category property on an external source (i.e. a collection of simple data transfer objects). I've tried setting it on the button but this doesn't work as i suspect it needs to be set on the DTO itself.

I've looked at your examples and tried any which way but loose but to no avail. Any ideas?

Here's a rough example of what i'd like to happen..

    <ribbon:PopupGallery InitialColumnCount="4" CanFilter="True" IsSelectionHighlightVisible="False" >
        <ribbon:PopupGallery.CategorizedItemsSource>
            <MultiBinding Converter="{StaticResource ObjectInstancesConverter}">
                <Binding Path="Collection1"></Binding>
                <Binding Path="Collection2"></Binding>
            </MultiBinding>
            </ribbon:PopupGallery.CategorizedItemsSource>
            <ribbon:PopupGallery.ItemTemplate>
            <DataTemplate>
                <ribbon:SplitButton ribbon:PopupGallery.Category="{Binding Path=A_Enum_Val}" 
    ImageSourceLarge="{DynamicResource MyImage}" Label="{Binding Path=Name}" VariantSize="Large" />
 
            </DataTemplate>
        </ribbon:PopupGallery.ItemTemplate>
    </ribbon:PopupGallery>
Thanks in advanced

JK

Comments (10)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

Your conclusion is correct. The actual items referenced by CategorizedItemsSource need to have the PopupGallery.Category attached property set on them. This also means that the items must derive from DependencyObject, so you can set the attached property.

Alternatively, you can create a wrapper object that derives from DependencyObject. It would wrap your actual data object, and expose it via a property (which you could then access in your DataTemplate).

The DataTemplate is really only used for display purposes, so it's not available to the PopupGallery to use for categorization.


Actipro Software Support

Posted 10 years ago by John Kelly
Avatar
Thanks for pointing me in the right direction. Just to be nice ;) i thought i'd post the wrapper that solved it.


    public class PopupGalleryCategoryWrapper<T> : DependencyObject
    {
        public T WrappedObject { get; private set; }

        public PopupGalleryCategoryWrapper(T wrappedObject, string category)
        {
            WrappedObject = wrappedObject;
            Category = category;
        }

        public string Category
        {
            get { return (string)base.GetValue(CategoryProperty); }
            set { base.SetValue(CategoryProperty, value); }
        }

        public static readonly DependencyProperty CategoryProperty =
            PopupGallery.CategoryProperty.AddOwner(typeof(PopupGalleryCategoryWrapper<T>));
    }
JK
Posted 10 years ago by John Kelly
Avatar
Oppps... Forgot to close the thread. :)
Posted 8 years ago by Alex B
Avatar
Hi,
I have a similar issue to the one John described. I have data bound the ribbon gallery's SelectedItem and CategorizedItemsSource to properties on a view model.

Your suggestion to create an object that wraps a data object would not work for our scenario as we are excluding dependency objects from our view model layer.

In this case regard, the PopupGallery implementation is difficult to properly incorporate into a MVVM pattern. If you exposed a way to set the source of the CollectionViewSource this would make this more feasible.

This issue is very important to our team. Will you consider implementing an alternative way to apply categorization?

Thanks very much,

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

Right now there is a protected virtual PopupGallery.GetCategorizedItemsSource method that returns the IEnumerable that ends up getting used as the CollectionViewSource.Source. The default implementation of that method returns the CategorizedItemsSource property value.

Once the CollectionViewSource is set up, a GroupDescription is applied to it that provides the groups and a Filter is applied based on the currently selected category.

Does that help explain things better? If you still can't achieve categorization, what specifically would you suggest as a way to improve things?


Actipro Software Support

Posted 8 years ago by Alex B
Avatar
Thanks for your response. I misspoke when I mentioned the source of the CollectionViewSource. Since our issue is with the fact that the attached property must be on each item, we would need some way to work around this necessity. Our items are view models and we don't want UI types (PopupGallery.Category, and DependencyObject) in the view models.

One way that this could be done would be to enable the use of a standard GroupDescription in place of the PopupGalleryItemGroupDescription. I would imagine that if there was a string property on the popup gallery that the user could specify the name of the property on their items which would be passed to base PropertyGroupDescription constructor. If this property on PopupGallery is not set, then you could fall back to the PopupGalleryItemGroupDescription.

Thanks in advance,

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

Unfortunately it's not that simple. The category needs to be retrieved from numerous locations:
* A filter items method (when a category is selected)
* The GroupDescription
* A method that determines the available categories.

What if we made a protected method on PopupGallery that you could override, something like:
string GetItemCategory(object item)

And have it default to using the attached property lookup.


Actipro Software Support

Posted 8 years ago by Alex B
Avatar
I see your point, if you just used a regular GroupDescription (with a property path set), then you could not access the group description property when you filter by the category.

Unfortunately, your suggested solution would still violate our architecture (but for different reasons). This is because the GetItemCategory method would need to reference the view model layer in order to know which property to get off each item. We don't want the area of the code base that contains our UI controls to have a dependency on our view models.

The only work around I can think of is to have a delegate property that would be set in xaml from the data context of the gallery. This could be called inside of GetItemCategory to get the category property off of a non-dependency object. So that's probably the approach we will take if you are able to provide the GetItemCategory method you mentioned.

Thanks again for your help with this matter. How long do you think it would be before you could release an update with the change you described?

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

Ok we've added a PopupGallery.ItemCategoryDelegate property for the next build. We're not sure when the next build will be since we just released one. The next one may actually be a 2011.2 version and could be a month or two out.

We could possibly give you a private build with this feature to tide you over. E-mail us if you'd like that.


Actipro Software Support

Posted 8 years ago by Alex B
Avatar
Thanks for making that change. I think we will wait until the next release.

AB
The latest build of this product (v2018.1 build 0675) 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.