我对一件可能非常简单的事情感到困惑。
我进行了搜索,但未能找到我需要的确切答案。
问题如下。
我正在自学Silverlight MVVM。
目前,我正在编写一个使用1个主页和2个用户控件的应用程序。
正如您所想象的那样,有3个视图模型。
目前在我的XAML中:
mainpage.xaml
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:newFileupload.ViewModel"
xmlns:vw="clr-namespace:newFileupload.View"
<UserControl.DataContext>
<vm:MainPageViewModel />
</UserControl.DataContext>
<Grid x:Name="LayoutRoot" Background="White">
<vw:PicturesOverviewView />
</Grid>
PicturesOverviewView.xaml
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
在mainpage.xaml中,我在xaml中设置了数据上下文,然后在网格中调用用户控件,如下所示:
<vw:PicturesOverviewView />
这让我遇到了以下错误:
Error 1 Cannot create an instance of "PicturesOverviewView". C:\Programming\C#\newFileUpload\newFileupload\MainPage.xaml 16 9 newFileupload
我完全不知道是什么原因导致了这个问题,其次...
我该如何将视图模型绑定到适当的用户控件上?
我需要为每个用户控件声明视图命名空间,然后像主页面一样设置它的数据上下文吗?
感谢您花时间阅读,希望能够尽快继续 :)