这是我的代码隐藏:
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/