Adorner 会破坏 MVVM 吗?

发布于 2024-08-25 23:32:09 字数 419 浏览 1 评论 0原文

我正在使用 MVVM 开发 WPF 应用程序。我的大多数视图只有 xaml 标记,后面的代码中没有任何内容(默认样板除外)。

除了一个视图之外,当我想禁用整个屏幕时,我使用装饰器来“黑化”屏幕。

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        //todo: transfer to modelview
        contentAreaAdorner = AdornerLayer.GetAdornerLayer(contentArea);
        waitingAdorner = new WaitingAdorner(contentArea);
    }

可以吗?或者有更好的方法在我的视图模型中实现这一点吗?

I'm developing a WPF app using MVVM. Most of my views have only xaml markup and nothing (except default boilerplate) on code behind.

All except one view that I use adorners to "blacken" the screen with when I want to disable the whole screen.

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        //todo: transfer to modelview
        contentAreaAdorner = AdornerLayer.GetAdornerLayer(contentArea);
        waitingAdorner = new WaitingAdorner(contentArea);
    }

Is that ok? Or is there a better way to implement this in my viewmodel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东北女汉子 2024-09-01 23:32:09

减少代码隐藏是 MVVM 的好处,而不是目标

MVVM 的目的是让 UI 逻辑更简单、更可测试。如果将此方法移至视图模型中,您的代码会更简单且更易于测试吗?很可能不会;事实上,情况可能并非如此。所以不用担心。

Reducing code-behind is a benefit of MVVM, not the goal.

The purpose of MVVM is to make UI logic simpler and more testable. Would your code be simpler and more testable if you moved this method to your view model? Very probably not; in fact it might be less so. So don't worry about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文