I have a column which has some cells that have their Style property set to Button. In my CreationFilter I want to change the text in the ButtonUIElement but it has no Text property? The reason I want to do this is that I need to be able to indent the text with a few space characters without changing the underlying data. The level of indent depends on a complex bit of logic so I figured the CreationFilter is the way to do it. How do I do I change the text on the ButtonUIElement?
Any ideas?
The ButtonUIElement class actually does expose a Text property. It would seem possible that you are referencing the instance as a UIElement, which is the base class from which all elements derive, and does not expose a Text property. If this is the case, you just have to upcast this reference to type ButtonUIElement.
I do the upcast but the Text property is read only apparently?
Hi,
You probably need to derive your own UIElement class from ButtonUIElement. Something like this:
public class MyButtonUIElement : ButtonUIElement { public MyButtonUIElement(UIElement parent) : base(parent) { } protected override void PositionChildElements() { base.PositionChildElements(); this.textElement.WrapText = true; } protected override void InitAppearance(ref AppearanceData appearance, ref AppearancePropFlags requestedProps) { base.InitAppearance(ref appearance, ref requestedProps); appearance.ThemedElementAlpha = Alpha.Transparent; appearance.ForeColor = Color.Black; } protected override bool ButtonClick() { return base.ButtonClick(); } }
You can set the Text property on the element when you create it.
Is there any way to wrap the text of ButtonUIElement ?
The reason why I need this is , I have a button which is larger in Height and lesser in width. And I need to assign a longer text to ButtonUIElement.
Now my button is hiding most of the text since it's width is lesser than my text length. is there any way to wrap the text in ButtonUIElement.
I have found that I can achieve this by using FormattedTextUIElement. But i could not set the appearance property to FormattedTextUIelement.
My need is , I have to wrap the text and I have to set the Appearance to the UIElement. Also I need to consume the click event. I can use any UIElement which satisfies these requirement. Please help me to achieve this.
Thanks in Advance.
I took a quick look and it appears that the cell creates a CellButtonUIElement which contains a DependentTextUIElement.
The DependentTextUIElement is an element which gets it's text from a provider, so it's not easy (and may not be possible) to change the text of this element.
So... what I would do is use the AfterCreateChildElements on the CreationFilter and trap for the CellButtonUIElement. Then you can simply remove the DependentTextUIElement from it's ChildElements collection and add in a new TextUIElement. You can then assign the Text property of the TextUIElement to whatever you want.