locked
Botton with images in XAML RRS feed

  • Question

  • Hi,

    What is the basic and simple way? to define button in XAML having:

    1) Default image (released)

    2) "Pressed" image

    3) "Disabled" image

    I dont plan to manipulate these images in "code-behind". I wish to define the batton and the images in XAML and for botton to behave just as ower-drawn buttons in Win32-Windows-GDI application.

    Regards,

    Monday, April 11, 2011 4:24 PM

Answers

  • You can create a custom button class that derives from Button. Add 3 dependency properties in that class

    1. DefaultProperty 

    2. PressedProperty

    3. DisabledProperty


    Create a style for this button in which you put 3 images and bind their source with the above defined properties.

    Define visual states for Default, pressed and disabled and set the opacity of these images accordingly.


    Then you can use this button as

    <CustomButton DefaultProperty= "a.png" DisabledProperty ="b.png" PressedProperty ="c.png" />

    Hope this helps.



    Monday, April 11, 2011 4:44 PM
  • Tuesday, April 12, 2011 10:33 PM

All replies

  • You can create a custom button class that derives from Button. Add 3 dependency properties in that class

    1. DefaultProperty 

    2. PressedProperty

    3. DisabledProperty


    Create a style for this button in which you put 3 images and bind their source with the above defined properties.

    Define visual states for Default, pressed and disabled and set the opacity of these images accordingly.


    Then you can use this button as

    <CustomButton DefaultProperty= "a.png" DisabledProperty ="b.png" PressedProperty ="c.png" />

    Hope this helps.



    Monday, April 11, 2011 4:44 PM
  • Tuesday, April 12, 2011 10:33 PM
  • I assume this should be done in Expression Studio, possibly following the guide below, which is rather long. I will do it, but it will take me a while to get it working.

    Thursday, June 9, 2011 2:27 AM