locked
click event for a image in WPF RRS feed

  • Question

  • i wanted to apply the msdn style of "Ask a question" in one of WPF control but without luck.

    However when i used with a image control it worked with the condition that it cannot have the cliked event as it is not a button.

    <Image Width="118" Height="35" Margin="371,295,129,111"><Image.Style>

    <Style TargetType="{x:Type Image}">

    <Setter Property="Source" Value="..\Images\light.png" />

    <Style.Triggers>

    <Trigger Property="IsMouseOver" Value="True">

    <Setter Property="Source" Value="..\Images\dark.png" />

    </Trigger>

    </Style.Triggers>

    </Style>

    </Image.Style>

    </Image>

    Saturday, December 1, 2012 8:11 PM

Answers

All replies

  • Just use a button and retemplate the style to be the image you want.  Then you have best of both worlds clickable events and images within the button.

    <Button Command="{Binding Path=DisplayProductCommand}" >
       <Image Source="..\Images\my-beautiful-product.jpg"/>
    </Button>


    JP Cowboy Coders Unite!

    Saturday, December 1, 2012 8:28 PM
  • but how do i achive onmouse over property; the idea is the image should change with mouse over and mouse out events.

    Thanks

    Monday, December 3, 2012 6:26 AM
  • You could use MouseEnter event and MosueLeaver event, if you want your Image handle the click event, you could use MouseDown event.


    Sheldon _Xiao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Monday, December 24, 2012 10:45 AM
    Monday, December 3, 2012 8:10 AM
  • Hi NabX,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 24, 2012 10:46 AM