Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
910
Custom EditorWithLabel Control
posted

Hi,

I want to have something similar to the UltraTextEditor->ButtonRight propertey.

But instead of a button I want to have an additional TextUIElement, so I tried to write my own via CreationFilter. But why is the TextUIElement dissapearing if I enter the edit mode.

The creation filter code:

public class AddLabelCreationFilter : IUIElementCreationFilter
{
public void AfterCreateChildElements(UIElement parent)
{
if (parent is EditorWithTextUIElement)
{
EditorWithTextUIElement editorUIElement = parent as EditorWithTextUIElement;
TextUIElement txtElem = new TextUIElement(parent, "AB");

int xPos = editorUIElement.Rect.Width - 40;

txtElem.Rect = new Rectangle(xPos, 1, 40, editorUIElement.Rect.Height);

UIElement dispElem = editorUIElement.ChildElements.FirstOrDefault(x => x is EditorWithTextDisplayTextUIElement);

if (dispElem != null)
{
dispElem.Rect = new Rectangle(dispElem.Rect.X, dispElem.Rect.Y, dispElem.Rect.Width - 40, dispElem.Rect.Height);
}

editorUIElement.ChildElements.Add(txtElem);
}
}

public bool BeforeCreateChildElements(UIElement parent)
{
return false;
}

}

Parents
No Data
Reply
  • 23930
    Verified Answer
    Offline posted

    Hi Michael,

     

    Thank you for posting in our forums.

     

    The reason why your additional text element disappears when you enter edit mode is because the control displays a Microsoft TextBox control over its edit area when in edit mode. This TextBox is what hides your TextElement and it will always occupy the whole edit area. What I suggest to do in order to resolve this, is to add a button to the ButtonsRight collection of the editor and then to use its rectangle for the text element. You can hide the Button by using a DrawFilter to skip its drawing.

     

    I have attached a sample which demonstrates this suggestion.

     

    Please let me know if you have any additional questions.

    WE_SecondTextEditor.zip
Children
No Data