typeloadexception未被用户代码

时间:2015-12-24 05:26:18

标签: c# xaml windows-phone-8.1 prism

在模拟器中运行应用程序时出现以下错误。应用程序构建没有错误。我使用VS2015 CE和棱镜库。

  

找不到Windows运行时类型'Windows.UI.ApplicationSettings.SettingsPane'。“

这就是我的解决方案的样子 enter image description here

这是程序停止的地方 enter image description here

XAML:

<prism:MvvmAppBase
    x:Class="MainModule.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MainModule"
    xmlns:prism="using:Microsoft.Practices.Prism.StoreApps">

</prism:MvvmAppBase>

CS:

using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Activation;
using Microsoft.Practices.Unity;
using System.Globalization;
using Microsoft.Practices.Prism.StoreApps;



// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=391641

namespace MainModule
{
    public sealed partial class App : MvvmAppBase
    {
        private readonly IUnityContainer _container = new UnityContainer();
        public App()
        {
            this.InitializeComponent();
        }

        protected override Task OnLaunchApplication(LaunchActivatedEventArgs args)
        {
            NavigationService.Navigate("Main", null);
            return Task.FromResult<object>(null);
        }

        protected override void OnRegisterKnownTypesForSerialization()
        {
            // Set up the list of known types for the SuspensionManager
            //SessionStateService.RegisterKnownType(typeof(Address));
        }

        protected override void OnInitialize(IActivatedEventArgs args)
        {
            _container.RegisterInstance(NavigationService);
            //_container.RegisterType<IAccountService, AccountService>(new ContainerControlledLifetimeManager());
            //_container.RegisterType<IShippingAddressUserControlViewModel, ShippingAddressUserControlViewModel>();

            //as  function says, it sets default view type to viewmodel, for an example it sets HubViewModel to HubView
            ViewModelLocator.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            {
                var viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "UIViewModelsLibrary.ViewModels.{0}ViewModel, UIViewModelsLibrary, Version=1.0.0.0, Culture=neutral", viewType.Name);
                var viewModelType = Type.GetType(viewModelTypeName);
                return viewModelType;
            });
        }

        protected override object Resolve(Type type)
        {
            return _container.Resolve(type);
        }
    }
}

我的MainPage文件(FacultyPage几乎相同)

的Xaml:

<prism:VisualStateAwarePage
    x:Class="ViewsLibrary.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ViewsLibrary.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prism="using:Microsoft.Practices.Prism.StoreApps" mc:Ignorable="d"
    prism:ViewModelLocator.AutoWireViewModel="true"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Button Content="Go To Faculty" 
            Command="{Binding GoBackCommand}"/>
    </Grid>
</prism:VisualStateAwarePage>

cs文件:

using Microsoft.Practices.Prism.StoreApps;

namespace ViewsLibrary.Views
{

    public sealed partial class MainPage : VisualStateAwarePage
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
}

视图模型:

using Microsoft.Practices.Prism.StoreApps;
using Microsoft.Practices.Prism.StoreApps.Interfaces;

namespace UIViewModelsLibrary.ViewModels
{
    class MainViewModel : ViewModel
    {
        public MainViewModel(INavigationService navService)
        {

            NavigateCommand = new DelegateCommand(() => navService.Navigate("Faculty", null));
        }

        public DelegateCommand NavigateCommand { get; set; }
    }
}

现在我是Windows Phone编程的新手,而我正在尝试创建的框架可以作为我的一些应用程序的基础。但这个错误已经花了我几个小时。

0 个答案:

没有答案