繁体   English   中英

在“MenuPage”类型中找不到属性“ViewModel”

[英]The Property 'ViewModel' was not found in type "MenuPage'

我正在尝试将 MVVM 架构用于 gui。 我有一个页面(MenuPage.xaml),其中有一个TextBox

<Page
    x:Class="AutoTranscriber.MenuPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AutoTranscriber"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>

        <StackPanel x:Name="contentPanel" Margin="468,305,161,208">
            <TextBlock HorizontalAlignment="Left" Text="Menu Page" FontSize="36"/>
            <TextBlock Text="Enter path to item image directory: "/>
            <StackPanel x:Name="folderInput" Orientation="Horizontal" Margin="0,20,0,20">
                <TextBox x:Name="pathToDirectory" Width="300" Height="32" Text="{x:Bind Path=ViewModel.input_folder, Mode=OneWay}"/>
                <Button x:Name="browseButtonFolder" Content="Browse" Click="browseButtonFolder_Click" Margin="5,0,20,0"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</Page>

我正在尝试将 TextBox 绑定到我的 ViewModel 的属性(x:Bind Path=ViewModel.input_folder...)。 我的 MenuPage.xaml.h 看起来像这样:

#pragma once

#include "MenuPage.g.h"
#include "MenuPageViewModel.h"

namespace Something
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    [Windows::Foundation::Metadata::WebHostHidden]
    public ref class MenuPage sealed
    {

    private:

        // button event handlers
        void browseButtonFolder_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);

    public:

        MenuPage();
        property MenuPageViewModel^ ViewModel;
    };
}

当然,我也有我的ViewModel class。 现在使用此设置,我在 MenuPage.xaml 中收到错误消息:

“在类型 'MenuPage' 中找不到属性ViewModel ”。

为什么我确实有ViewModel属性时会收到此错误,我该如何解决?

让我知道问题中是否缺少重要信息,并提前感谢您的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM