How to disable hide/unhide in WPF Ribbon Control - wpf

I am using the latest Ribbon Control from MS. When one double click the Tab Header, the whole Ribbon will hide the content and show only the header text. I want to disable this hide/unhide feature. So even if user double click Tab Header, the Ribbon remain as it is.
I think it should be the OnMouseDoubleClick Event in RibbonTab but have no clue how to override it. Am I suppose to give it a x:Name to each and every RibbonTab then write an empty method ribbonTab1_OnMouseDoubleClick to each Ribbon Tab?

Use the PreviewMouseDoubleClick event in the Ribbon:
PreviewMouseDoubleClick="ribbon_PreviewMouseDoubleClick"
and then in the handler, mark the event as handled:
private void ribbon_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}

Related

how to get Tabcontrol's Tab focus in WPF

I am New in WPF
I have one form on which I put one datagrid as well as there is one "Add New" button to add new item in grid
so is there any way to know about tab lost focus when click on Add new button and again get focus on tab control ? Lostfocus event of tab control does not work.
Thanks
You can make use of the TabControl.SelectionChanged Event
void TabControl_TabSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.Source is TabControl)
{
// do something
}
}

WPF combobox-like custom control

I would like to create custom control that will look like standard WPF ComboBox, but instead of instead of having an ItemsPresenter in the popup there will be another custom control. So, I created a new class that derives from System.Windows.Controls.Control, added a IsDropDownOpen property and created a style that is actually a copy of default ComboBox style (main idea is that the Popup.IsOpen and ToggleButton.IsPressed properties are bound to the IsDropDownOpen property of the control).
The problem is that the Popup is not closed when I click outside of the control.
I took a look at the ComboBox class in the Reflector and found out that ComboBox used some logic to update the IsDropDownOpen property when it loses mouse capture. But that code uses some internal classes. Is there any alternative way to determine if the user clicked outside of the control and close the Popup?
UPD: I didn't find the way to attach a file to post, so I uploaded sample project here
There is a custom control that looks like ComboBox, but it has a TreeView in a popup. When you open popup and click outside of the control it closes automatically, but if you open popup, expand 'Item2' and then click outside the popup isn't closed. The question is how to fix this?
There is the Control.LostFocus event, maybe handling that would be sufficient for this.
This code solves the problem.
In the static contructor:
EventManager.RegisterClassHandler(typeof(CustomComboBox), Mouse.LostMouseCaptureEvent, new MouseEventHandler(OnMouseCaptureLost));
Event handler implementation:
private void OnMouseCaptureLost(object sender, MouseEventArgs e)
{
if (Mouse.Captured != _container)
{
if (e.OriginalSource != _container)
{
Mouse.Capture(_container, CaptureMode.SubTree);
e.Handled = true;
}
}
}

wpf catching mouse down outside my custom control

I'm building a custom control in WPF. I want to catch a mouse down event when my control is in focus but the user clicks outside the control. Is there a way to do that and if so how?
My control inherits from ListBox.
You can use UIElement.CaptureMouse and it's partner UIElement.ReleaseMouseCapture to capture all mouse events to a single control, regardless of what the mouse was over when the event occurred.
In your example I would capture the mouse when the control has focus, and release the mouse when the control looses focus.
Suppose you have a Window with a TextBox on it.
By registering to Window's MouseDown event,
MouseDown += new MouseButtonEventHandler(Window_MouseDown);
You can use following code
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (TextBox1.IsFocused)
{
MessageBox.Show("TextBox1 in focus.");
}
}
To catch this event if TextBox1 is in focus.

Silverlight custom control ToolTip not showing up each time

In a Silverlight application I have a custom control with a number of custom properties. In the declaration class of the custom control additionally to defining its properties as dependency properties, I define showing a ToolTip:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Border bordercntr = base.GetTemplateChild("PART_SBorder") as Border;
bordercntr.MouseEnter += new MouseEventHandler(bordercntr_MouseEnter);
bordercntr.MouseLeave += new MouseEventHandler(bordercntr_MouseLeave);
}
private void bordercntr_MouseEnter(object sender, MouseEventArgs e)
{
string _sno = this.SomeProperty.ToString();
ToolTipService.SetToolTip(this, "Some text " + _sno);
VisualStateManager.GoToState(this, "Hovered",false);
}
The problem is, that a ToolTip pops up not the first time mouse points to a custom control, but only after the second time. After I reload page this happens again: the first time I hover over a control nothing is shown up and then from the second time and further on the ToolTip pops up again. (not always in a stable way, I mean not 100% each time mouse hovers).
What could prevent the ToolTip from showing up in a stable manner each time a mouse hovers over control and starting showing up from the very first time of hovering it after reloading the page?
Set the ToolTip in the setter for SomeProperty The ToolTip you define in the ToolTipService will behave like a normal ToolTip and only appear when the mouse is over the control. You shouldn't need to handle the MouseEnter and MouseLeave events at all.

ToolStrip Buttons flashes

I have a windows form with a toolstip in it with several buttons.
When the mouse is over a button of the toolstip then the toolstrip button starts to flash... looks like it gets and loses focus every second.
That results for the click to do nothing if the user click at the time that the button has no focus therefore the user has to click the button again and again util he gets the timing correct.
Does anyone knows anything about this?
I rally need some answers as soon as possible...
Thank you very much
I have found the reason...
The toolstrips in windows forms have by default the tooltips set to Auto and if the tooltip opens on the taskbar then the toolstrip loses focus.
The solution to this is to either disable the tooltips or to set it to manual and show the tooltip at another place.
Here is the code for showing the tool tip above the item manually:
private readonly ToolTip currentToolTip = new ToolTip();
private void ToolStripItem_MouseEnter(object sender, EventArgs e)
{
ToolStripItem item = (ToolStripItem)sender;
this.currentToolTip.Show(item.ToolTipText, item.Owner, item.Bounds.X, -20);
}
private void ToolStripItem_MouseLeave(object sender, EventArgs e)
{
ToolStripItem item = (ToolStripItem)sender;
this.currentToolTip.Hide(item.Owner);
}
You have to add the event handlers to all your ToolStripItems and set the ToolStrips' ShowItemToolTips to false.

Resources