Hello to all,
i do have quite a simple question:
How can i disable a GalleryItem ?
I am populating the items dynamically in Code Behind.
Depending on the Application State, some Selections are not allowed, so i want to disable the related items.
A workaround would be a filtering of the items when my Appliocation state changes, but i dont like that very much.
I know , its not really the proposed way to work with a ribbon gallery, but at this time i would like to go that way.
Any suggestions are welcome.
Thanks
Thomas
Hello Thomas,
In order to disable a GalleryItem, I would recommend that you write a Style for GalleryItemPresenter. From there you can use the Style’s Triggers or a converter on a setter for IsEnabled to determine the enabled status of the corresponding GalleryItem. The GalleryItem itself will be the data context of the GalleryItemPresenter and so that it what you will be binding to if not using a RelativeSource binding.
I am attaching a sample project that demonstrates the ability to disable the GalleryItem.
Please let me know if you have any other questions or concerns on this matter.
XamRibbonDisableGalleryItem.zip
Hi Andrew,
thanks for your quick answer.
It points me to the right direction, what i would like to accomplish is to set the enabled state of the items in code behind.
The items itself also are added in code behind.
Thanks,
i played around with these things and came to the following solution.
I derived my own class from GalleryItem and added a "IsEnabled" Dependency Property.
Using your idea, i created a style:
<Style x:Name="galleryPresentStyle" x:Key="galleryPresentStyle" BasedOn="{x:Null}" TargetType="{x:Type ig:GalleryItemPresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding IsEnabled}" Value="False"> <Setter Property="IsEnabled" Value="False" /> <Setter Property="Opacity" Value="0.5"/> </DataTrigger> </Style.Triggers> </Style>
The trigger is bound to the "IsEnabled" property of the derived GalleryItem.
The 2 setters disable the item and set the visual style to disabled by using the Opacity property.
Thanks for pointing me into the right direction.....