Hello,
Using Infragistics2.Win.UltraWinToolbars.v10.3, I have been trying to host a custom WPF UserControl in the WinForms ribbon using a ControlContainerTool containing an ElementHost.
Whilst the designer correctly renders the component, when running the ElementHost region is rendered as an opaque blue colour. The component is there (you can type, copy text etc). But it is not visible.
Is this supported? Do you expect it to be able to work? Can you suggest anything to get it working?
Sample project: here.
Hi Boris,
I've now (thankfully) resolved this issue. It came down to a misunderstanding over the lifecycle of the Control. The Control is disposed when the ribbon is minimized.
Remove the overridden get-UIElement-related methods and instead lazily rebuilding the Control resolved the issue.
Best wishes,
Alex
Hello Alex,
Please attach a sample project of this, since I am not sure already how to reproduce your scenario and we will investigate this for you.
Boris,
I wonder whether you can help with a further issue that has arisen?
If the ribbon is minimized and the tab containing the widget is clicked (to reveal the tab's tools), the element is sometimes displayed in the wrong position.
It is as if the widget is being repositioned to an offset relative to the Form's origin, rather than an offset on the ribbon tab's origin.
Any suggestions to fix this?
Thank you,
Thank you for your feedback again.
Please feel free to let me know if a question about our toolset comes up on your mind.
Answering my own question again, in case others also desire this functionality. The only approach I have found to work is hooking the AfterRibbonTabSelected event. Giving something like this:
using System;
using System.Runtime.Serialization;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinToolbars;
namespace CustomTools
{
public class UniqueInstanceControlContainerTool : ControlContainerTool
public override Control Control
get
SynchronizeVisibleSetting();
return UnderlyingControl;
}
public UniqueInstanceControlContainerTool(string key)
: base(key)
Control = new TextBox();
public UniqueInstanceControlContainerTool(SerializationInfo info, StreamingContext context)
: base(info, context)
protected override ToolBase Clone(bool cloneNewInstance)
var tool = new UniqueInstanceControlContainerTool(Key);
tool.InitializeFrom(this, true);
return tool;
protected override void Initialize(ToolsCollectionBase parentCollection)
base.Initialize(parentCollection);
RegisterEvents();
private void RegisterEvents()
if (ToolbarsManager != null)
// This allows us to show/hide the underlying Control to the tab it is located on.
// Strangely, this doesn't seem to be natively supported by the underlying ControlContainerToolUIElement.
ToolbarsManager.AfterRibbonTabSelected += ToolbarsManagerOnAfterRibbonTabSelected;
private void ToolbarsManagerOnAfterRibbonTabSelected(object sender, RibbonTabEventArgs ribbonTabEventArgs)
private UIElement GetControlContainerToolUIElement(ToolBase tool, UIElement parentElement,
UIElement previousElement, bool drawAsActive,
bool drawAsPressed)
var containerToolUiElement = new ControlContainerToolUIElement(parentElement, tool, Control);
return containerToolUiElement;
protected override UIElement GetRibbonToolUIElement(ToolBase tool, UIElement parentElement,
return GetControlContainerToolUIElement(tool, parentElement, previousElement, drawAsActive, drawAsPressed);
protected override UIElement GetToolbarUIElement(ToolBase tool, UIElement parentElement,
protected override bool IsContainedControlShared
get { return false; }
protected override ToolBase ToolWithContainedControl
get { return this; }
protected override void OnSubObjectPropChanged(PropChangeInfo propChange)
base.OnSubObjectPropChanged(propChange);
protected override void OnVisibleChanged()
base.OnVisibleChanged();
private void SynchronizeVisibleSetting()
var sourceTool = this as ToolBase;
var control = UnderlyingControl;
Type expectedParentType = typeof (UltraToolbarsDockArea);
UltraToolbarsManager toolbarsManager = sourceTool.ToolbarsManager;
if (toolbarsManager == null)
return;
if (control == null)
var ribbonGroup = sourceTool.Owner as RibbonGroup;
if (ribbonGroup != null)
RibbonTab tab = ribbonGroup.Tab;
if (tab != null)
if (tab != toolbarsManager.Ribbon.SelectedTab)
control.Visible = false;
if (!sourceTool.VisibleResolved)
if (!control.Visible)
else
if (control.Visible || sourceTool.UIElement == null)
Control parent = control.Parent;
if (parent == null || !expectedParentType.IsAssignableFrom(parent.GetType()))
control.Visible = true;