如何添加一个命令到WPF TextBlock? [英] How to a add a command to a WPF TextBlock?

查看:1893
本文介绍了如何添加一个命令到WPF TextBlock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要能够点击一个文本块,并让它运行一个命令。这可能吗?
(如果不是,我只是以某种方式在它上面做了一个透明按钮或什么?)

I'd like to be able to click a textblock and have it run a Command. Is this possible? (if not do I just somehow make a tranparent button over it or something?)

推荐答案

InputBinding

<TextBlock Text="Hello">
    <TextBlock.InputBindings>
        <MouseBinding Command="" MouseAction="LeftClick" />
    </TextBlock.InputBindings>
</TextBlock>

编辑:Hyperlink可能值得一提。

Hyperlink is probably worth a mention too.

<TextBlock><Hyperlink Command="" TextDecorations="None" Foreground="Black">Hello</Hyperlink></TextBlock>

这篇关于如何添加一个命令到WPF TextBlock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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