gpt4 book ai didi

.net - 为 TextBlock 启用命令绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 20:26:37 25 4
gpt4 key购买 nike

我正在开发一个 WPF 应用程序,并且有一个 TextBlock,我想在单击时使用命令绑定(bind)来触发命令。实现这一目标的最佳方法是什么?

  • TextBlock 控件没有 Command 属性,但它有 CommandManager。这是什么?它可以用于命令绑定(bind)吗?我还看到了许多其他具有此属性的控件..
  • 是否有一些我监督过的可以使用的控制?是不是例如建议使用按钮并将其样式设置为看起来不像按钮?
  • 是否有一些支持命令绑定(bind)的控件,我可以将它们包裹在 TextBlock 周围?
  • 我是否应该创建一个基本上是 TextBlock 的自定义控件,但具有额外的属性 Command 和 CommandArgument 可以启用命令绑定(bind),例如MouseLeftButtonDown 属性。
  • 最佳答案

    Is there some control I have overseen that can be used? Is it e.g. recommended to use a button and style it to not look like a button?



    是的。最简单的方法是将按钮重新模板化,使其像 TextBlock 一样,并利用按钮类的命令属性。

    像这样的东西:
    <ControlTemplate TargetType="Button">
    <TextBlock Text="{TemplateBinding Content}" />
    </ControlTemplate>
    ...
    <Button Content="Foo" Command="{Binding Bar}" />

    关于.net - 为 TextBlock 启用命令绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1789975/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com