locked
Can I display a xaml Page from JS Windows Store application?

    Question

  • I have a C# library (WindowsRuntimeComponent), with xaml Pages. Can I somehow display those pages in JS Windows Store Application? Please help.

    Thanks a lot!

    Greetings

    Monday, April 22, 2013 12:17 PM

Answers

  • Nope--sharing UI between HTML/CSS/JS and XAML layers is not supported, plain and simple.

    .Kraig

    Monday, April 22, 2013 3:50 PM
  • Yes, I'm totally sure. The rendering process for HTML/CSS is entirely separate and isolated from anything XAML does, and there simply is not a means to have the two interoperate. Put another way, the mechanisms that are being employed on the CoreWindow level for a running app (as I understand it) means that any UI you might attempt to do from a XAML component simply has no window into which it can render. Whether the code that invokes Windows.UI.Xaml API is in the app or a library makes no difference, as that's all app code as far as the system is concerned.

    It should be noted that a C#/C++ component can call non-XAML APIs that result in UI such as message dialogs, the file picker, etc., as those aren't related to XAML. But that, of course, is not custom UI.

    A component can also create bitmaps that can then be displayed from the JS side, but that's pretty limited and non-interactive.

    But let me ask you this. You suggest that you're turning to JS because of a .NET bug, with the idea that you want to do all your UI from C#/XAML and use JS to do some kind of work that is blocked by the bug. You're also suggesting that if you would write a WinRT component in JavaScript (which isn't an option), then you could work around the bug by having the JS engine do some bit of work that's affected by the bug.

    If that's the case, then why can't you write a WinRT component in C++ to do that same work? If the blocking bug is in the CLR (.NET runtime), then C++ is also running independently of that and likely doesn't have the bug.

    As a result, you can write most of the app in C#/XAML but rely on the one bit of C++ as a workaround.

    Monday, April 22, 2013 5:22 PM

All replies

  • Nope--sharing UI between HTML/CSS/JS and XAML layers is not supported, plain and simple.

    .Kraig

    Monday, April 22, 2013 3:50 PM
  • Thank you for your answer.
    I don't want to be rude, but I really, really need this. Are you sure? Even if I have it in another library? Even if I don't want to mix XAML with JS (as many questions on MSDN suggest), but display the whole page object (created with XAML and C#)?

    I'm affraid, I have found a bug in .NET (still checking this out), thats why for now I have to use JS (cuz it works there). Unfortunatly, there is no possibility to create JS library in Windows Store Solution, which forces me to create main project as JS app.

    My problem is I have already written a lot of things in C# using XAML for this project. I also have a pretty good experience with C# and XAML, but almost no experience with JS and HTML - thats why it's so important for me, not to convert my code to JS.

    Could you please just confirm, that by answering you meant all kind of 'sharing UI between HTML/CSS/JS and XAML' - that there is absolutely no possibility do do this.

    I need to be sure about this painfull truth.
    Thank you one more time,
    Greetings.

    Monday, April 22, 2013 4:46 PM
  • Yes, I'm totally sure. The rendering process for HTML/CSS is entirely separate and isolated from anything XAML does, and there simply is not a means to have the two interoperate. Put another way, the mechanisms that are being employed on the CoreWindow level for a running app (as I understand it) means that any UI you might attempt to do from a XAML component simply has no window into which it can render. Whether the code that invokes Windows.UI.Xaml API is in the app or a library makes no difference, as that's all app code as far as the system is concerned.

    It should be noted that a C#/C++ component can call non-XAML APIs that result in UI such as message dialogs, the file picker, etc., as those aren't related to XAML. But that, of course, is not custom UI.

    A component can also create bitmaps that can then be displayed from the JS side, but that's pretty limited and non-interactive.

    But let me ask you this. You suggest that you're turning to JS because of a .NET bug, with the idea that you want to do all your UI from C#/XAML and use JS to do some kind of work that is blocked by the bug. You're also suggesting that if you would write a WinRT component in JavaScript (which isn't an option), then you could work around the bug by having the JS engine do some bit of work that's affected by the bug.

    If that's the case, then why can't you write a WinRT component in C++ to do that same work? If the blocking bug is in the CLR (.NET runtime), then C++ is also running independently of that and likely doesn't have the bug.

    As a result, you can write most of the app in C#/XAML but rely on the one bit of C++ as a workaround.

    Monday, April 22, 2013 5:22 PM