Hi there,
Im trying to implement a special appearance to a button, with a title text and a larger description below it with different font color/size, like Windows Vista have in some messagebox. Its possible to do that with ultrabutton or another control?
Hi,
Well, one of the most obvious differences is that I used BeforeCreateChildElements instead of After, like you are doing. This is not really a big deal, but your way, the ImageAndTextUIElement and all of it's child elements are created and then you have to remove it. In my case, I am returning true from BeforeCreateChildElements, so the element never gets created in the first place. It's just a bit more efficient, but like I said, not really a big deal.
I am also placing the FormattedTextUIElement directly under the UltraBiuttonUIElement, which means the button won't show the Appearance.Image if you assigned one. I figured this was unlikely and you are probably not displaying an image on the button, anyway. You use of ImageAndFormattedTextUIElementEx might avoid that problem, but I am not entirely sure - it might work or it might not. If it doesn't work, it's likely because that element doesn't know how to get the Appearance.Image from the button because it's expecting to be a part of some other control. But I might be wrong.
Thank you very much for your fast and interesting reply.
In the meantime i had found a solution on my own but it doesnt seem very elegant to me. Could you please give a bit of comparison and discussion of the both so i can learn from it?
public void AfterCreateChildElements(UIElement parent) { var button = parent as UltraButtonUIElement; if (button == null) { return; } var originalUiElement = button.ImageAndTextElement; var replacementUiElement = new ImageAndFormattedTextUIElementEx(originalUiElement.Parent) { Rect = new Rectangle(originalUiElement.Rect.Location, originalUiElement.Rect.Size), TextHAlign = originalUiElement.TextHAlign, TextVAlign = originalUiElement.TextVAlign, Value = new ParsedFormattedTextValue(originalUiElement.Text) }; button.ChildElements.Remove(originalUiElement); button.ChildElements.Add(replacementUiElement); }
I have attached a working sample demonstrating how to do this.
I am trying to created a FormattedUltraButton based on the above suggestion and the custom uielement howto but i can't get it right. My code seems to work when i step through with a debugger but the visual result does not change at all. Here's my custom UIElementCreationFilter. Please advise.
public void AfterCreateChildElements(UIElement parent) { var button = parent as UltraButtonUIElement; if (button == null) { return; } var originalTextElement = button.ImageAndTextElement.TextElement; var formattedTextElement = new FormattedTextUIElement(button.ImageAndTextElement) { Rect = new Rectangle(originalTextElement.Rect.Location, originalTextElement.Rect.Size), Value = new ParsedFormattedTextValue("This is a <b>test</b>") // originalTextElement.Text }; button.ImageAndTextElement.ChildElements.Remove(originalTextElement); button.ImageAndTextElement.ChildElements.Add(formattedTextElement); }
UltraButton does not support mixed fonts as you describe here. One way to cheat this out would be to use te IUIElementCreationFilter interface to remove the TextUIElement is uses to display the text, and replace it with a Infragistics.Win.FormattedLinkLabel.FormattedTextUIElement, which does support mixed fonts. You could use the UltraFormattedLinkEditor control's Value property designer to format the text (the markup it recognizes is not exaclty the same as HTML) and then assign that value to the FormattedTextUIElement property.