在WPF中创建可点击的图像 [英] Creating a clickable image in WPF

查看:88
本文介绍了在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.

推荐答案

尝试这种非常简单的方法

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
        }

这篇关于在WPF中创建可点击的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆