as part of my custom control development for button control, i need to have a button content with a combination of the image
and a text (side by side). i need to change the image to a different image when i place my cursor on to the button and change to
original image when the mouse leaves the control.
how to acheive this in generic.xaml and my cs file?
Regards,
srinivas J
5 Answers, 1 is accepted
You can use the MouseEnter and MouseLeave events to change the picture in the button.
Could you please examine the attached sample project and tell me if it works for you?
Hello zarko,
Thanks for the reply. but here my requirement is for custom control development as mentioned in the earlier mail.the example you provided is useful for application level. I need it at framework level. I need to acheive this using custom template approach . i need to achieve this in the Generic.xaml .
The end result i would expect something like if i drag and drop my buttoncontrol from toolbox, it should have the default properties like ,
<mycustombutton ......contentimage="someimageurl " contentname="mybutton" />
if i say like this , then my button should have the feature to take the button image and name on to the button as a content and need to have my image be replaced by new one if i mouse over on it.
The problem for me is to write the template tag at the generic.xaml. if i get the look then i can write the logic to mouseover and leave.
Help me with your suggestions,
Regards,
Srinivas
I'm sorry for the miss understanding. Please take a look at the project that I've attached , there you can see how to write the template in the Generic.xaml. Notice that in order for this to work you have to register a ResourceDictionary in the App.xaml file.
All the best,Thank you very much reply.It helped me. Adding to the below requirement, the buttoncontrol i provide at the framework level which contains image and textblock placed on the content must have a previlage to allow the image and textblock
to arrange themselves to relative height and width with respective to button dimensions( height and width) . is there any properties supports them ?
Thanks in advance .
Srinivas
The Image and the TextBlock are in a StackPanel which fills the whole button, so if you don't explicitly set image size with the ContentImageHeight or ContentImageWidth the sizes of the image and the textblock are going to be relative to the button size. I hope this is what you are looking for and if you have further questions feel free to ask.
Greetings,