Reputation: 31
I am currently trying to open a XAML view from a C# class in a Windows 10 UAP WinJS project. To do that, I have a C# class I instantiate from javascript then I call a method on it to load the XAML view. However, when I call CoreApplication.CreateNewView(), it triggers an exception with the message "Value does not fall within the expected range.".
I wonder if I'm doing something wrong (I'm not used to Windows 10 Apps), or if it is simply not possible to Open XAML/C# view in a WinJS app.
Here is the JS code I use to call my C# code:
var csClass1 = new CsCode.Class1();
csClass1.loadXamlPage();
Here is the C# code which throws an exception:
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);
}
}
}
Upvotes: 3
Views: 163