gpt4 book ai didi

wpf - 如何使用ICommand实现DockPanel或图像单击?

转载 作者:行者123 更新时间:2023-12-03 10:52:05 30 4
gpt4 key购买 nike

这是我开始之前的一些背景知识。我开始在WPF中创建应用程序,就像在WinForms中编程一样。显然,这完全绕过了WPF的优势。因此,既然我已经阅读了有关WPF和MVVM框架的更多信息,那么我将开始调整我的应用程序,使其以模型- View - View 模型的方式工作。

以前,我曾经将代码隐藏在窗口的后面,只是处理了MouseDown RoutedEvents之后再继续并提示窗口进行签名。我的DockPanel和Image似乎没有Command

我该如何使用MVVM方法? RoutedEvents是否适合这种情况?

最佳答案

不用将整个行为和行为复杂化,而是将所有UI元素放在Button的ControlTemplate中并使用它的Command:

<Button Command="{Binding YourCommand}">
<Button.Template>
<ControlTemplate TargetType="Button">
<DockPanel>
<Image/>
<!-- Whatever -->
</DockPanel>
</ControlTemplate>
</Button.Template>
</Button>

关于wpf - 如何使用ICommand实现DockPanel或图像单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19796221/

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