Hi,
I am trying to have am image on the ButtonUIElement like the following:
Public Sub AfterCreateChildElements(ByVal parent As Infragistics.Win.UIElement) _
If TypeOf parent Is GroupBoxHeaderUIElement Then
btnAddProblems = ButtonUIElement(parent)
New Drawing.Size(parent.RectInsideBorders.Width - 125, parent.RectInsideBorders.Height))
btnAddProblems.Appearance.ImageBackground = img
at this point I am geetin NullException Error because btnAddProblems.Appearance is Nothing at this point
How could I resolve the probelm and and where should I write InitAppareance and how to invoke that method.
Please help.
Thanks.
Thanks everybody for all your help. Actually it woked after setting the ThemedElementAlpha of the appearance to Transparent.
Thank you very much.
I think this thread is getting a bit confused. So let's step back a moment.
First, you have posted your question in the WinGrid forum, but the element in your code is a GroupBoxHeaderUIElement, which has nothing to do with the grid as far as I know.
So to what, exactly, are you attempting to add a button?
Secondly, no matter where you are adding a button, you should not set the Appearance on the UIElement. This is never a good idea and probably won't work. If the element you are adding supports displaying images, then the proper way to supply an image would be to derive your own UIElement class and override InitAppearance. But I'm not entirely sure that ButtonUIElement supports images, so this may not work in this case.
If not, then the thing to do would be to have the CreationFilter add an ImageUIElement into the button during the call to BeforeCreateChildElements for the ButtonUIElement, and set the Image property on this ImageUIElement when you add it.
There are two possibilities here that I can think of. The first is that your button is drawing with themes, and so will not render the image; you can disable this by setting the ThemedElementAlpha of the appearance to Transparent. If you want to use an image (as opposed to ImageBackground), you would need to derive your own element from ButtonUIElement because by default the DrawImage method does nothing; therefore, you would have to override DrawImage and call it yourself through the drawParams object that is passed to the method.
I also wouldn't create an Appearance object each time, since this would be inefficient as this will happen every time the grid needs to recreate its child elements; instead, keep a cached Appearance object around. If you do want to use the InitAppearance method that you mentioned, you could create your own derived element and override the InitAppearance method; just make sure to call the base after you do your own processing.
-Matt
Its not giving me any error now but still not showing the image on the button . Do we need to override InitAppearance() method or so....
You can either create this appearance property ahead of time or right before you want to assign the imagebackground. So:
btnAddProblems.Appearance = new Appearance()
btnAddProblems.Appearance.ImageBackground = img;
or:
Dim myApp as Appearance = new Appearance()
myApp.ImageBackground = img
then later:
btnAddProblems = myApp
(my syntax might not be 100%, I entered the code directly into this box)