wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

Porting existing WPF to NoesisApp

03 May 2019, 17:21

Hi,

I made a little program in WPF and tries to port it to Noesis, no Unity.
I have looked at all the examples that could be downloaded but did not succeed.

Main problem is that i get errors like: partial class "App"/ "MainWindow"/ etc must specify a diferent base class.
And even if i get rid of those errors, it complains about "StartupUri not set" wich is defined in App.xaml but not in the file App.cs ( wich in any of the examples is also not set).

Is there any Tutorial on how to do this from scratch?...

EDIT:
I have tried different .net solutions: .net 4.6.1 / .NetCore / .net Standard.

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Porting existing WPF to NoesisApp

03 May 2019, 18:14

Hi, if you download the Managed SDK (C#) you will find there lots of examples that contain Blend WPF projects sharing all the contents with projects using Noesis for different platforms.

To convert an existing WPF project to Noesis the steps would be:

1. Create a project for the desired platform
  • Windows -> .NET 4.61, .NetCore, Forms...
  • UWP -------> UWP 10.0.16299 (min)
  • Android --> Xamarin.Android
  • iOS ---------> Xamarin.iOS
  • macOS ----> Xamarin.Mac, .NetCore
  • Linux ------> Mono, .NetCore
2. Install from NuGet the appropriate Noesis Display and RenderContext packages for each platform.
  • Windows -> Noesis.App.Displays.Win32, Noesis.App.RenderContexts.D3D11
  • UWP -------> Noesis.App.Displays.WinRT, Noesis.App.RenderContexts.D3D11
  • Android --> Noesis.App.Displays.Android, Noesis.App.RenderContexts.EGL
  • iOS ---------> Noesis.App.Displays.UIKit, Noesis.App.RenderContexts.MTL
  • macOS ----> Noesis.App.Displays.AppKit, Noesis.App.RenderContexts.MTL
  • Linux ------> Noesis.App.Displays.X11, Noesis.App.RenderContexts.GLX
3. Create application entry point code. You can copy App.cs from our samples and adapt it to your needs. For example, the code for a windows application would look like this:
using System;
using NoesisApp;

namespace Buttons
{
    partial class App : Application
    {
        protected override Display CreateDisplay() { return new Win32Display(); }
        protected override RenderContext CreateRenderContext() { return new RenderContextD3D11(); }

        [STAThread]
        static void Main()
        {
            App app = new App() { Uri = "App.xaml" };
            app.Run();
        }
    }
}
4. Adjust WPF-Noesis code differences using conditional compilation symbols:
#if NOESIS
using Noesis;
using NoesisApp;
#else
using System;
using System.Windows;
using System.Windows.Controls;
#endif

namespace Buttons
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.Initialized += OnInitialized;
            this.InitializeComponent();
        }

#if NOESIS
        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "MainWindow.xaml");
        }
#endif

        private void OnInitialized(object sender, EventArgs args)
        {
            this.DataContext = new ViewModel();
        }
    }
}
5. Set xaml files and other resources Build Action to "Embedded Resource" if you are using the default application resource providers. You can also use Local providers that search for resources in the local directory, or even create your own.

To simplify this process we have plans to create Visual Studio project templates that will do steps 1 to 3 automatically, and we also want to be able to generate InitializeComponent code-behind for controls, so named elements and events are automatically connected.

Please let us know if you need further assistance.
 
wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: Porting existing WPF to NoesisApp

03 May 2019, 20:38

Thank you,

The problems went away with step 5.

Cant wait for VS Templates, and maybe more Intellisence support?..

I feel this can be so much more then the "Game engine gui middle-man"!
 
mehmet yonugul
Posts: 1
Joined: 17 May 2019, 12:24

Re: Porting existing WPF to NoesisApp

14 Sep 2019, 13:20

Is it working on linux?
Framework of the sample project is .Net 4.6.2 for c# project.
Is there any sample project for c# working on linux?
 
JaredThirsk
Posts: 25
Joined: 04 Feb 2015, 23:20

Re: Porting existing WPF to NoesisApp

16 Jun 2020, 21:13

Any thoughts about adding a netcoreapp3.1 Sample?

In case it helps anybody, here's what I had to do to create a .NET Core 3.1 version of the ApplicationTutorial-windows. Haven't gotten the theme working (NoesisTheme.DarkBlue from Noesis.GUI.Extensions), but it is otherwise working:
(I'm not sure if this is the best way to do it. There is also EmbeddedFileProvider.)
  public partial class App : Application
    {
        protected override XamlProvider CreateXamlProvider() => new NetCoreXamlProvider();
    }
    public class NetCoreXamlProvider : XamlProvider
    {
        public override Stream LoadXaml(string filename)
        {
            var embeddedProvider = new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly());
            return embeddedProvider.GetFileInfo(filename).CreateReadStream();
        }
    }
csproj:
  <ItemGroup>
    <EmbeddedResource Include="..\Src\Samples\ApplicationTutorial\Src\App.xaml" Link="App.xaml">      
    </EmbeddedResource>
    <EmbeddedResource Include="..\Src\Samples\ApplicationTutorial\Src\MainWindow.xaml" Link="MainWindow.xaml">
    </EmbeddedResource>
  </ItemGroup>
Set GenerateEmbeddedFilesManifest to true:
 <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>ApplicationTutorial_windows_netcore</RootNamespace>
    <StartupObject>RssReader.App</StartupObject>
    <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
  </PropertyGroup>
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Porting existing WPF to NoesisApp

18 Jun 2020, 12:50

Hi,

I was able to make ApplicationTutorial sample work (without modifying any source file and using the same App.cs from windows project) with .NET Core 3.1 using the following project:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>RssReader</RootNamespace>
    <AssemblyName>ApplicationTutorial</AssemblyName>
  </PropertyGroup>

  <PropertyGroup>
    <DefineConstants>TRACE;NOESIS</DefineConstants>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="..\..\Src\App.xaml.cs" Link="App.xaml.cs" />
    <Compile Include="..\..\Src\MainWindow.xaml.cs" Link="MainWindow.xaml.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Noesis.App.Displays.Win32" Version="3.0.2" />
    <PackageReference Include="Noesis.App.RenderContexts.D3D11" Version="3.0.2" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="..\..\Src\App.xaml" Link="App.xaml" />
    <EmbeddedResource Include="..\..\Src\MainWindow.xaml" Link="MainWindow.xaml" />
  </ItemGroup>

</Project>
No problems with the theme and I didn't have to add the GenerateEmbeddedFilesManifest to True, what error did you get without that property?

The only weird thing I noticed is that after including the xaml files in the project they didn't show up in the Solution explorer, so I had to edit the .csproj manually to change xamls to a EmbeddedResource type. Did you have the same problem?
 
JaredThirsk
Posts: 25
Joined: 04 Feb 2015, 23:20

Re: Porting existing WPF to NoesisApp

19 Jun 2020, 04:42

Thanks for your example csproj. It turns out, I was missing the <RootNamespace> element. Setting that to RssReader got it working.
(Without it, it can't find the App.xaml.)
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Porting existing WPF to NoesisApp

19 Jun 2020, 16:51

Glad to help.

We are thinking on adding a -netcore project to our next SDK samples to make clear it is supported. Although we are still providing VS 2017 projects and I don't think 3.1 is available there, so we would have to stick to 2.1 version.

Who is online

Users browsing this forum: No registered users and 1 guest