我目前正在尝试从 Windows 10 UAP WinJS 项目中的 C# 类打开 XAML View 。 为此,我有一个从 javascript 实例化的 C# 类,然后在其上调用一个方法来加载 XAML View 。 但是,当我调用 CoreApplication.CreateNewView() 时,它会触发异常并显示消息“值不在预期范围内。”。
我想知道我是否做错了什么(我不习惯 Windows 10 应用程序),或者根本不可能在 WinJS 应用程序中打开 XAML/C# View 。
这是我用来调用我的 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);
}
}
}
最佳答案
您无法从 WinJS 应用程序打开 c#/XAML 控件
关于c# - 从 WinJS 应用打开 C#/XAML View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31943349/