WPF Ribbon collapse and expand programmatically - c#

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?

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.

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.

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

Related

Is it possible to disable a control but still receive events for that control?

In windows forms I have a simple TextBox:
TextBox textBox = new TextBox() { Text = "text" };
textBox.Enabled = false;
textBox.MouseEnter += (object sender, EventArgs e) =>
{
MessageBox.Show("MOUSE ENTERED"); // this never fires if the control is disabled.
};
I want to disable the users ability to interact with the control and I want the control to be styled as a disabled control. But I also want to receive MouseEnter,MouseLeave, and Click events from the control so that I can change the background cover of the control on hover and respond to clicks on the control.
But as I have just discovered if you disable a windows forms control it disabled the events as well. I know with some effort I can accomplish the same thing by checking mouse coordinates globally but it would be a lot nicer if I could just have it disabled but still receive events for it. Is that possible?
Enabled doesn't really do anything in Windows Forms itself. It is a property of windows controls in general that a disabled window doesn't receive input messages (such as mouse events and keyboard events). So no, there is no way for you to disable a control and still receive those messages. Windows just don't work that way on Windows. It's not the TextBox control filtering those messages away - they don't come in the first place.
TextBox is a great wrapper around a windows common control. When you do something like tbx.Text = "Hello";, the TextBox just sends a message to that common control, saying "change the text to Hello". If you want to change that, you need to make the control essentially from scratch. You can make some hack that reverts whatever the common control does as response to a mouse event, but these usually don't work very well and tend to break down in unexpected ways.
In practice, what you really want is probably to tweak either the way ReadOnly behaves (e.g. disabling focus as well as making the control read only, but that's again just a dirty hack), or replace the TextBox with a control that can either be a control or a label - allowing you to switch between the two. If you want the text box to stop behaving as a text box, stop it from being a text box. Problem solved :)
I'd still reconsider using ReadOnly, though. Are you sure the user would not want to select text in the text box and copy it somewhere else? Or change the reading order?

Hide Dev Express AplicationMenu

I'm using Dev Express Ribbon Control to load different views in my WPF Application.
I would like to be able hide/close the Application Menu at run-time when I want, and let the view that needs to be displayed to fit all the size of the screen.
I tried something like this but it didn't work as expected :
this.ApplicationMenu.BackstageClosed += (s, e) =>
{
this.ApplicationMenu
.GetType()
.GetProperty("IsBackStageViewOpen")
.SetValue(this.ApplicationMenu, false);
};
Here's a image of the application, and I'm trying to hide the left Application menu when the view present in the right part is loaded.
I suggest you create an implicit style for the RibbonControl type. In this style, create a trigger for the RibbonControl.ApplicationMenu property and set the RibbonControl.ShowApplicationButton property to false if the menu is empty.

Cannot remove custom ribbon controls from quick access toolbar (QAT) menu

I have a custom addin for Word (could also be for Excel).
The addin has a ribbon with multiple groups and multiple controls (buttons) within them.
This is an ongoing project and some of the ribbon buttons are for users, and some are for testing/development purposes.
When I send the product to the client I only show certain buttons. I want the testing buttons to be completely invisible/inaccessible. I Have tried setting the testing buttons/groups to visible = false.
This works, in the sense that the buttons do not appear on the ribbon, but if the user goes to Word's quick access toolbar > "More Commands" > "Choose Commands From" dropdown and selects my custom addin...
Then the user can see all of my buttons. Even the ones with no label.
I have tried looping the controls in the ribbon load method and setting the testing controls to enabled = false, locked = true, generatemember = false, but none of these hide the buttons from the QAT menu. I also tried control.Dispose() - no joy.
Is there anyway to set the properties of a ribbon button such that it is completely invisible and inaccessible to the user in the QAT??
Many thanks
Set the ApplicationMode.
Button CommandName='cmdExportMetadata' ApplicationModes='1'
Please see the below link too :
https://msdn.microsoft.com/en-us/library/windows/desktop/dd940486(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ee264330(v=vs.85).aspx
I would suggest you to create debug buttons dynamically. Define a constant variable like public constant string environment = "DEBUG"; and check it on start up

devcomponents ribbon bar quick access toolbar

I trying to use the Quick access toolbar on Dev Components Ribbon Bar, it works fine if I set it in the designer.
But if I change the 'CanCustomize' flag on a 'BaseItem' on the form load event the customize dialog does NOT pick this up.
I wondered if there is a command I can call to tell the ribbon bar to redefine itself?
or if I have to redefine the ribbon bar entirely?
I have tried calling RecalcLayout as beloww
BaseItem.CanCustomize = false
RibbonBar.RecalcLayout()
but it does not work.
Hi have figured out what works for this.
BaseItem.visible = false
this will stop it from being shown on the QAT, but it will still be visible on the customize menu, i still want to stop some of these being shown, but have NOT figured that out yet.

Enable/Disable Ribbon Buttons in Word 2007 Addin

Currently i am working on a word Addin, where i have added controls to the ribbon dynamically. Now, I need to catch the dynamic button "btnSubmit" and based on the condition i need to enable/disable the button.
when the document is opened for the first time it should be enabled and Once the Button is clicked it should be disabled.
This should be done on a boolean condition. Any help would be greatly appreciated.
thanks,
KSR Prasad
It is possible through RibbonXML using the getEnabled event.
Ribbon XML:
<button id="button1" onAction="button1_Click" getEnabled="button1_EnabledChanged" />
Code:
public void button1_Click(Office.IRibbonControl control)
{
if (control.Id == "button1")
{
// your code
clicked = true; // a boolean variable
}
}
public bool button1_EnabledChanged(Office.IRibbonControl control)
{
if (control.Id == "button1")
return !clicked;
}
If you've already created the button, just create a regional scope WITHEVENTS variable to hold it in, assign it, then react to the click event to disable the button (the button object has an enabled property).
Private WithEvents _MyButton As Ribbon.RibbonButton
....
Set _MyButton = {the just created button}
then handle the click event
My preference for this type of issue is to use RibbonXml rather than the designer.
A really simple option would be have a Dictionary which you can then store in the ribbon callback class. If you wanted a nicer option, VSTO Contrib (http://vstocontrib.codeplex.com/) allows you to create a 'viewmodel' per document quite easily, then you simply can bind the button enabled to a property on the viewmodel.
More info on ribbon xml: http://jake.ginnivan.net/vsto-ribbon-designer-in-depth
More info on vsto contrib and how it can help you: http://jake.ginnivan.net/vsto-contrib/ribbon-factory
Cheers,
Jake

Categories

Resources