Search code examples
wpfmvvmmvvm-foundationclickable-image

Creating a clickable image in WPF


I want to make a user control that shows an image and can invoke a command when clicked. Later I want to bind a list of these controls to a list of products.


Solution

  • Try this very straight forward approach

    <Grid>
            <Button Height="50" Width="50">
                <Button.Template>
                    <ControlTemplate>
                        <Image Source="yourimage.png"/>
                    </ControlTemplate>
                </Button.Template>
            </Button>
    
        </Grid>
    
    private void Button_Click(object sender, RoutedEventArgs e)
            {
               // do smt
            }