8

With the latest (October 2010) WPF Ribbon libraries, there exists a menu item to minimize/maximize (or collapse/expand, if you prefer) the ribbon control.

Does anyone know if there's also a way to hook into the events that control this behaviour so that it could be controlled programmatically from separate UI? Or, better yet, is there a way to get a collapse/expand button to display in the ribbon like the 2010 Office apps do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mark Atkinson
  • 161
  • 2
  • 7

3 Answers3

7

You can use the boolean property IsMinimized on the Ribbon class to show/hide the ribbon itself. It is a dependency property, so you can bind to its value to support the scenarios you describe.

As far as I know, the default template does not have a show/hide button, like Office does, but it shouldn't be too hard to modify the template (using Blend) to add one.

madd0
  • 9,053
  • 3
  • 35
  • 62
  • Thanks. I've tapped into that property and also the SizeChanged event on the ribbon itself. I'll probably hold off on modifying the template. – Mark Atkinson Mar 16 '11 at 21:23
1

If what you need is know when the bar gets minimized (this happens when you double click a tab header) you could hook to the IsMinimizedChanged event, but er.. it is missing. Hopefully it is a DependencyProperty so you can successfully hook to any DependencyProperty change this way:

DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon)) .AddValueChanged(ribbon, (o, args) => /* your code here */);

What I wanted to do (and hence got here) is to prevent it from minimizing when double clicking the header so I ended up using this code:

DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon)) .AddValueChanged(ribbon, (o, args) => ribbon.IsMinimized = false);

Is not so fancy but gets the job done.

Guillermo Ruffino
  • 2,940
  • 1
  • 26
  • 23
0

Add a toggle button(simple button and set its content to v or ^ depending upon the operation requested) and then you can use ContentControl in button click to fulfill your requirement:

     ContentControl contentControl = FindVisualChildataBankyName<ContentControl>(rbnName, "mainItemsPresenterHost");
     contentControl.Visibility = System.Windows.Visibility.Collapsed;

Use contentControl.Visibility = System.Windows.Visibility.Visible; in order to maximize the ribbon