Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Ribbon collapse and expand programmatically

Tags:

c#

.net

wpf

ribbon

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?

like image 406
Mark Atkinson Avatar asked Mar 09 '11 22:03

Mark Atkinson


2 Answers

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.

like image 106
madd0 Avatar answered Nov 01 '22 00:11

madd0


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.

like image 31
Guillermo Ruffino Avatar answered Oct 31 '22 23:10

Guillermo Ruffino