wpf - 将代码后面的代码转移到 wpf 中的 View 模型

标签 wpf mvvm icommand

这是我的代码隐藏:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            foreach (FrameworkElement fe in canvas.Children)
            {
                double top = (double)fe.GetValue(Canvas.TopProperty);
                double left = (double)fe.GetValue(Canvas.LeftProperty);
            }
        }

“ Canvas ”是我在 XAML 中的 Canvas 控件的名称。当前代码为我提供了获取 Canvas 内图像位置的能力。这是在代码隐藏中实现的。问题是,我们如何以 MVVM 方式获取图像的位置(使用命令启动进程)?

最佳答案

how we get the location of images in MVVM manner(using the command to start the process)?



不需要命令,只需将每个 Canvas 的每个所需属性绑定(bind)到 VM。然后在需要时提取获取图像所需的目标 Canvas 属性。

关于wpf - 将代码后面的代码转移到 wpf 中的 View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36475312/

相关文章:

c# - C# ActionCommand :ICommand into VB.net 翻译

mvvm - WPF MVVM 命令 CanExecute,仅在焦点更改时重新评估

WPF 和 MVVM : Get values from textboxes and send it to ViewModel

c# - 如何向图像添加 JPEG 注释 (COM)?

design-patterns - MVVM 本身是一种观察者模式吗?

c# - 为什么这个数据网格需要额外的绑定(bind)语法?

MVVM-Light:我们应该把 Messenger 的寄存器放在哪里

c# - 如何在 WPF 应用程序中使用 windows 键

WPF ContextMenu 单击路由到 WinForms 应用程序

wpf - 在 Watermark 附加属性中绑定(bind) TextBox.Text 以将其本地化