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?
I have attached a working sample demonstrating how to do this.
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); }
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.