问题描述
我有一个主窗口,网格将窗口水平分成两半。
在上面的窗口中,我有几个按钮和一个数据网格,其中包含我正在搜索的目录。
底部窗口有一个清除按钮和一个显示搜索结果的数据网格视图。
如何为上部窗口声明SearchViewModel和XAML中底部窗口的ResultsViewModel?
据我所知,我只能在主窗口XAML中声明一个ViewModel。为什么我不能在XAML中为每个半部分声明数据上下文并将每个数据网格绑定到它们各自的ViewModel?
我必须遗漏一些基本的东西。
感谢您的帮助。
I have a main window with a grid dividing the window in half horizontally.
In the upper window I have a couple of buttons and a datagrid that holds the directories I'm searching.
The bottom window has a clear button and a datagrid view that displays the results of the search.
How can I declare the SearchViewModel for the upper window and the ResultsViewModel for the bottom window in XAML?
As far as I can tell I can only declare one ViewModel in the main window XAML. Why can't I have a data context declared in XAML for each of the halves and bind each datagrid to their respective ViewModel?
I must be missing something basic here.
Thanks for your help.
推荐答案
这篇关于具有多个视图模型的MVVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!