Hi,
I want to add a button on ultraExplorerBar's group header(before the expansion indicator). Please let me know if its possible to do the same. I am using Infragistics Ver4.3.
I have tried the following code but could not able to add the button. Used creation filter.
public
void AfterCreateChildElements(Infragistics.Win.UIElement parent)
{
if(parent is UltraExplorerBarGroupHeaderUIElement)
ButtonUIElement
btnClose = (ButtonUIElement)parent.ChildElements[0].GetDescendant(typeof(ButtonUIElement));
if(btnClose ==null)
btnClose =
new ButtonUIElement(parent);
btnClose.Text =
"Close";
parent.ChildElements.Add(btnClose);
}
Hello,
In your creation filter, you also need to specify the rectangle (Rect) for the new UIElement you are adding. Here is a sample creation filter I quickly put together to demonstrate this. Note that I derived a new ButtonUIElement so I could override the OnClick() as well as make the descendant search easier:
public class ExplorerBarGroupCloseButtonCreationFilter : Infragistics.Win.IUIElementCreationFilter { #region IUIElementCreationFilter Members public void AfterCreateChildElements(Infragistics.Win.UIElement parent) { if (parent is UltraExplorerBarGroupHeaderUIElement) { // find the close button CloseGroupButtonUIElement closeButton = parent.GetDescendant(typeof(CloseGroupButtonUIElement)) as CloseGroupButtonUIElement; if (closeButton == null) { // get the group UltraExplorerBarGroup group = parent.GetContext(typeof(UltraExplorerBarGroup)) as UltraExplorerBarGroup; if (group != null) { // create a new close button closeButton = new CloseGroupButtonUIElement(parent, group); // create the rectangle // depending on the Style, you may need to adjust the location to aviod the Expansion button. Rectangle parentRect = parent.RectInsideBorders; closeButton.Rect = new Rectangle(parentRect.Right - 40, parentRect.Y, parentRect.Height - 2, parentRect.Height - 2); // add the element to the collection parent.ChildElements.Add(closeButton); // to avoid overlapping the text, you should adjust the text UIElement here. // ... } } } } public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent) { return false; } #endregion } public class CloseGroupButtonUIElement : ButtonUIElement { private UltraExplorerBarGroup group; #region Constructor public CloseGroupButtonUIElement(UIElement parent, UltraExplorerBarGroup group) : base(parent) { this.group = group; this.Text = "X"; } #endregion //Constructor #region Base Class Overrides public override UIElementButtonStyle ButtonStyle { get { return UIElementButtonStyle.ScenicRibbonButton; } } protected override bool DrawTheme(ref UIElementDrawParams drawParams) { return false; } protected override void OnClick() { if (this.group != null) this.group.ParentCollection.Remove(this.group); base.OnClick(); } protected override void OnDispose() { this.group = null; base.OnDispose(); } #endregion //Base Class Overrides }
Let me know if you have any further questions.
Thanks,
Chris
Thanks Chris...its working perfectly...