BackstageItems Binding and Templating

May 26, 2010 at 5:16 AM
Edited May 26, 2010 at 5:17 AM

Hi all,

I was looking for a way to bind the Ribbon.BackstageItems to a collection of ViewModels but couldn't really find a way to do it so I ended up adding my own attached property which clears and adds the backstage items when the property is changed.
i.e.

		public static readonly DependencyProperty BackstageItemsProperty = DependencyProperty.RegisterAttached(
		  "BackstageItems",
		  typeof(ReadOnlyCollection<BackstageItemViewModel>),
		  typeof(RibbonExtension),
		  new PropertyMetadata(OnBackstageItemsChanged));

		public static ReadOnlyCollection<BackstageItemViewModel> GetBackstageItems(DependencyObject obj)
		{
			return (ReadOnlyCollection<BackstageItemViewModel>)obj.GetValue(BackstageItemsProperty);
		}

		public static void SetBackstageItems(DependencyObject obj, ReadOnlyCollection<QuickAccessItem> value)
		{
			obj.SetValue(BackstageItemsProperty, value);
		}

		static void OnBackstageItemsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
		{
			var ribbon = obj as Ribbon;
			if (ribbon != null)
			{
				ribbon.BackstageItems.Clear();

				var newValue = (ReadOnlyCollection<BackstageItemViewModel>)args.NewValue;
				foreach (var newItem in newValue)
				{
					var tabItem = new BackstageTabItem();
					tabItem.Header = newItem.Caption;
					tabItem.Content = newItem;
					tabItem.ContentTemplate = GetBackstageItemContentTemplate(obj);
					tabItem.ContentTemplateSelector = GetBackstageItemContentTemplateSelector(obj);
					ribbon.BackstageItems.Add(tabItem);
				}
			}
		}

 

My questions are:

  1. Does the above workaround seem reasonable or is there a standard way of doing it that I wasn't aware of?
  2. I would like to set the BackstageTabItem.Header to be a ContentPresenter so I could provide different templates, etc. through XAML. It seems to me that currently the header can only be set to a string instance? There is also no HeaderTemplate or HeaderTemplateSelector on the BackstageTabItem class even though the Header is actually of type object (not string).
  3. BackstageItems collection is actually a collection of UIElement, but I couldn't seem to add any UIElement there. I was going to solve number 2 by adding ContentPresenters to the BackstageItems collection. Is there a way to do this?

Any help would be greatly appreciated and thanks for writing a great control library.

Ted

Jun 1, 2010 at 7:00 AM

Hi, This is fairly urgent for us, any updates? 

Thanks in advance,

Ted

Jun 15, 2010 at 1:28 AM

Hi - is anyone monitoring and maintaining this control suite?

A number of posts are going un-answered for nearly a month.

The above issue is urgent for us and will affect our decision to use the control.

Coordinator
Jun 15, 2010 at 2:20 PM

Do you need something like ItemsSource for Ribbon.BackstageItems? Right?

Jun 15, 2010 at 11:11 PM
Hi daVinci, Yes. ItemsSource would be great. We also need to be able to define the ItemTemplate and/or the ItemTemplateSelector. Also as per my 2nd question above, is there a way to specify the content of the header as XAML elements instead of just a string? Thanks
Jun 16, 2010 at 10:19 AM
tburhan wrote:
Hi daVinci, Yes. ItemsSource would be great. We also need to be able to define the ItemTemplate and/or the ItemTemplateSelector. Also as per my 2nd question above, is there a way to specify the content of the header as XAML elements instead of just a string? Thanks

http://fluent.codeplex.com/Thread/View.aspx?ThreadId=214848

Is this thread answering what are you looking for?

Jun 17, 2010 at 12:01 AM

Hi varely,

No, that's not quite what I was looking for. I would like to use ViewModels to bind to the BackstageItems.

Thanks,

Ted

Jun 22, 2010 at 2:47 PM
I too would like to use ViewModels to bind to the Backstage Items. Thanks, Shawn
Coordinator
Jun 22, 2010 at 4:35 PM

Backstage items & Backstage buttons issues will be fixed in v2 (this summer)
Thanks

Jun 28, 2010 at 8:04 PM

I would love to have that feature too, but for Tabs and or RibbonGroups. So, that i am able to create separate Tab and / or a set of RibbonGroups which are assigned to a my ViewModels. Currently, i could create my own CustomControl (derived from RibbonGroupsContainer) but i am not able to bind it to a tab. Or do i miss something?

@tburhan: Would it be possible, that you post the Implementation of this:

tabItem.ContentTemplate = GetBackstageItemContentTemplate(obj);
tabItem.ContentTemplateSelector = GetBackstageItemContentTemplateSelector(obj);

 I am still a bit new to WPF :-(

Thanx,

Chris

Jul 7, 2010 at 12:13 AM

Hi Chris,

The GetBackstageItemContentTemplate() and GetBackstageItemContentTemplateSelector() were simply getter methods for the attached properties to store the ContentTemplate and ContentTemplateSelector for the BackstageTabItem.

The implementation is pretty simple - see below.

Hope that helps

        public static readonly DependencyProperty BackstageItemContentTemplateProperty = DependencyProperty.RegisterAttached(
          "BackstageItemContentTemplate",
          typeof(DataTemplate),
          typeof(RibbonExtension));

        public static DataTemplate GetBackstageItemContentTemplate(DependencyObject obj)
        {
		return (DataTemplate)obj.GetValue(BackstageItemContentTemplateProperty);
        }

	public static void SetBackstageItemContentTemplate(DependencyObject obj, DataTemplate value)
        {
                obj.SetValue(BackstageItemContentTemplateProperty, value);
        }