Hi,
I'm using UltraOptionSet.
I want that its text will be on its left side instead of its right side.
How can I do this?
Thanks,Yael
Hi Yael,
There's no property for this on the control, but you can do it using a CreationFilter, and it's a pretty simple one.
public class MyUltraOptionSetCreationFilter : IUIElementCreationFilter { #region IUIElementCreationFilter Members void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { // Do nothing } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { OptionSetOptionButtonUIElement optionSetOptionButtonUIElement = parent as OptionSetOptionButtonUIElement; if (optionSetOptionButtonUIElement != null) { optionSetOptionButtonUIElement.CheckAlign = ContentAlignment.MiddleRight; } return false; } #endregion }
Hi Mike,
How can i user this with optionset?
How can I extend this class with my base Control Class?
It's still not clear to me exactly what you want. You want the text and the radio button both to be centered? Seems like a very strange UI to me. The radio buttons would not be lined up and you would have sort've jagged edges on both sides. That's really what you want?
Here's some sample code that centers the items within the control. I think it looks kinda weird, but if that's what you want, this should do it.
public class MyCreationFilter : IUIElementCreationFilter { void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if (parent is OptionSetEmbeddableUIElement) { foreach (UIElement element in parent.ChildElements) { if (element is OptionSetOptionButtonUIElement) { Rectangle rect = element.Rect; DrawUtility.AdjustHAlign(HAlign.Center, ref rect, parent.RectInsideBorders); element.Rect = rect; } } } } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { // Do nothing return false; } }
It works for one option only.. If I add 2nd option, it overlapes on first..
what to do now??
Did you modify the code I posted here? I tested this in an OptionSet with 5 items and it worked fine for me with no overlap.
Maybe you could post a small sample project demonstrating the behavior you are getting.
Mike, PFA for sample code.
The code is not working for me.
Thank you so much Mike,
Cheers............
Okay, not I see why your question didn't make sense to me in the first place. Your OptionSet is only tall enough to show one item. The sample code I posted here is intended for an OptionSet where the items are displayed vertically. If you make the OptionSet in your sample taller, you will see that all of the items are centered.
To center everything like you seem to want is a lot more complex. You have to get all of the elements, figure out the total width needed, then offset each element.
public class MyUltraOptionSetCreationFilter : Infragistics.Win.IUIElementCreationFilter { #region IUIElementCreationFilter Members void Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements(Infragistics.Win.UIElement parent) { if (parent is Infragistics.Win.OptionSetEmbeddableUIElement) { int? left = null; int? right = null; foreach (Infragistics.Win.UIElement element in parent.ChildElements) { if (element is Infragistics.Win.OptionSetOptionButtonUIElement) { Rectangle rect = element.Rect; if (left == null) left = rect.Left; else left = Math.Min(left.Value, rect.Left); if (right == null) right = rect.Right; else right = Math.Max(right.Value, rect.Right); } } if (left.HasValue && right.HasValue) { int requiredWidth = right.Value - left.Value; int availableWidth = parent.RectInsideBorders.Width; int newLeft = (availableWidth - requiredWidth) / 2; int offset = newLeft - left.Value; if (offset != 0) { foreach (Infragistics.Win.UIElement element in parent.ChildElements) { element.Rect = new Rectangle( element.Rect.X + offset, element.Rect.Y, element.Rect.Width, element.Rect.Height); } } } } } bool Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements(Infragistics.Win.UIElement parent) { return false; } #endregion }
public class MyUltraOptionSetCreationFilter : Infragistics.Win.IUIElementCreationFilter { #region IUIElementCreationFilter Members void Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements(Infragistics.Win.UIElement parent) { if (parent is Infragistics.Win.OptionSetEmbeddableUIElement) { int? left = null; int? right = null; foreach (Infragistics.Win.UIElement element in parent.ChildElements) { if (element is Infragistics.Win.OptionSetOptionButtonUIElement) { Rectangle rect = element.Rect; if (left == null) left = rect.Left; else left = Math.Min(left.Value, rect.Left); if (right == null) right = rect.Right; else right = Math.Max(right.Value, rect.Right); } } if (left.HasValue && right.HasValue) { int requiredWidth = right.Value - left.Value; int availableWidth = parent.RectInsideBorders.Width; int newLeft = (availableWidth - requiredWidth) / 2; int offset = newLeft - left.Value; if (offset != 0) { foreach (Infragistics.Win.UIElement element in parent.ChildElements) { element.Rect = new Rectangle( element.Rect.X + offset, element.Rect.Y, element.Rect.Width, element.Rect.Height); } } } } } bool Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements(Infragistics.Win.UIElement parent) { //Infragistics.Win.OptionSetOptionButtonUIElement optionSetOptionButtonUIElement = parent as Infragistics.Win.OptionSetOptionButtonUIElement; //if (optionSetOptionButtonUIElement != null) //{ // //optionSetOptionButtonUIElement.Rect = new Rectangle(parent.Rect.X, parent.Rect.Y + 1, parent.Rect.Width - 2, optionSetOptionButtonUIElement.Rect.Height - 1); // optionSetOptionButtonUIElement.CheckAlign = ContentAlignment.MiddleLeft; // optionSetOptionButtonUIElement.TextHAlign = Infragistics.Win.HAlign.Center; //} return false; } #endregion }