gpt4 book ai didi

wpf - 命名空间中不存在名称 ViewModelLocator

转载 作者:行者123 更新时间:2023-12-02 20:00:23 28 4
gpt4 key购买 nike

我正在使用 MVVM Light 学习 WPF,但我的可移植类库存在问题。我按照这个教程:http://www.codeproject.com/Articles/536494/Portable-MVVM-Light-Move-Your-View-Models

我引用MVVM Light创建了一个门户类库和一个WPF mvvm light 4.5。我已经在我的 wpf 项目中添加了我的 PCL 的引用。因此,在我的 PCL 中,我添加了一个文件夹 ModelView 并在我的 ModelViewLocator 中

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using EasyDevis.EasyDevisPCL.Model;
using EasyDevis.EasyDevisPCL.ViewModel.MainPage;

namespace EasyDevis.EasyDevisPCL.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class ViewModelLocator
{
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MainPageViewModel>();
}

/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public MainPageViewModel MainPageViewModel
{
get
{
return ServiceLocator.Current.GetInstance<MainPageViewModel>();
}
}

/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
}
}
}

问题出现在我的 app.xaml 中,并且命名空间是正确的,因为 intelisense 向我建议了路径。

<Application x:Class="EasyDevis.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:EasyDevis.EasyDevisPCL.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="Content/MainPage/View/MainPageView.xaml"
mc:Ignorable="d">

<Application.Resources>
<!--i've the error on this line-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>

</Application>

你知道我做错了什么吗?

最佳答案

迟到了,但我发现 ViewModelLocator.cs 有一个它引用的底层包被移动,并且阻止了它的构建(进而导致此错误,因为它“不存在”)

因此在 ViewModel/ViewModelLocator.cs 中进行更改

using Microsoft.Practices.ServiceLocation;

using CommonServiceLocator;

关于wpf - 命名空间中不存在名称 ViewModelLocator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23068222/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com