通用Windows平台中的MVVM绑定问题

通用Windows平台中的MVVM绑定问题,mvvm,uwp,binding,Mvvm,Uwp,Binding,好的,我正在使用VisualStudio和uwp。我创建了一个WeatheVM,作为资源绑定到我的页面。每次我创建资源时,它都会说“无法创建WeatheVM”。我很沮丧,我不明白为什么不让我,我需要这个来访问我的属性 <Page x:Class="uwpMVVM.View.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sche

好的,我正在使用VisualStudio和uwp。我创建了一个WeatheVM,作为资源绑定到我的页面。每次我创建资源时,它都会说“无法创建WeatheVM”。我很沮丧,我不明白为什么不让我,我需要这个来访问我的属性

<Page x:Class="uwpMVVM.View.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:uwpMVVM.View"
      xmlns:vm="using:uwpMVVM.ViewModel"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Page.Resources>
        <vm:WeatherVM x:Key="vm" />
    </Page.Resources>

    <Grid>

        <AutoSuggestBox x:Name="box"
                        Grid.Column="1"
                        Margin="40"
                        QueryIcon="Find"
                        />
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="53*" />
            <ColumnDefinition Width="247*" />
        </Grid.ColumnDefinitions>

    </Grid>
</Page>


顺便说一句,我的VM是一个公共类,在您给出的代码中,我看到您在
页面中创建了
WeathVM
。参考资料
,但没有引用它

您可以将网格的DataContext设置为vm,以便导入您创建的资源


假设要显示
Temp
属性。设置DataContext后,可以像这样绑定它


这是一个,您可以参照它进行修改


致以最诚挚的问候。

我知道,但我无法做到这一点。如果visual studio一直告诉我“无法创建WeatheVM”,因为我有几个类别,将其创建为资源密钥是有意义的,那么我可以执行以下操作:将网格的数据上下文绑定到天气。CurrentObservations我按照您告诉我的方式放置数据上下文,以及相同的错误Hi,您能否提供WeatherVM代码和当前页面的隐藏代码,这将有助于问题分析?