【问题标题】:Open C#/XAML view from a WinJS app从 WinJS 应用程序打开 C#/XAML 视图
【发布时间】:2015-08-11 13:36:30
【问题描述】:

我目前正在尝试从 Windows 10 UAP WinJS 项目中的 C# 类打开 XAML 视图。 为此,我有一个从 javascript 实例化的 C# 类,然后我在其上调用一个方法来加载 XAML 视图。 但是,当我调用 CoreApplication.CreateNewView() 时,它会触发异常并显示消息“值不在预期范围内。”。

我想知道是我做错了什么(我不习惯 Windows 10 应用程序),还是根本无法在 WinJS 应用程序中打开 XAML/C# 视图。

这是我用来调用我的 C# 代码的 JS 代码:

var csClass1 = new CsCode.Class1();
csClass1.loadXamlPage();

这是引发异常的 C# 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace CsCode
{
    public sealed class Class1
    {
        public async void loadXamlPage()
        {
            //throw "Value does not fall within the expected range." exception
            Windows.ApplicationModel.Core.CoreApplicationView newView = CoreApplication.CreateNewView();

            int newViewId = 0;
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame = new Frame();
                frame.Navigate(typeof(MainPage1), null);
                Window.Current.Content = frame;
                newViewId = ApplicationView.GetForCurrentView().Id;
            });
            bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);

        }
    }
}

【问题讨论】:

  • 陷入同样的​​境地。如果你发现了什么,请告诉我。

标签: c# xaml winjs win-universal-app


【解决方案1】:

您无法从 WinJS 应用程序打开 c#/XAML 控件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多