wyvern010
Topic Author
Posts: 31
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.
 
User avatar
sfernandez
Site Admin
Posts: 2983
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: 31
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: 2983
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: 2983
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.
 
AvtsVivek
Posts: 1
Joined: 03 Apr 2023, 07:51

Re: Porting existing WPF to NoesisApp

04 Apr 2023, 10:24

Is there a .net core working example? Simple Wpf Noesis sample and no unity.

Struggling for the last two days, but couldn't get it to work.

Just wanted to start from scratch.

I tried this example here (https://github.com/AvtsVivek/NoesisWpf/ ... pfBasicApp).

But in the console, I get the following messages.

[NOESIS/I] Noesis Init v3.2.0 (Windows on x86_64 Profile)
[NOESIS/I] Inspector listening on port 17629
[NOESIS/E] Can't find resource name 'App.xaml' in 'NoesisWpfBasicApp' assembly, clear <RootNamespace> in your .csproj to embed resources as plain paths
[NOESIS/E] Xaml not found '/NoesisWpfBasicApp;component/App.xaml'
[NOESIS/E] Can't load 'MainWindow.xaml', use Uri with assembly when loading XAML files. For example: '/YourAssembly;component/MainWindow.xaml'
[NOESIS/E] Xaml not found 'MainWindow.xaml'

Also the MainWindow is not correct. For example, it has a button, but it does not show up.

```xml
<Window x:Class="NoesisWpfBasicApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:local="clr-namespace:NoesisWpfBasicApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button>Here we go...</Button>
</Grid>
</Window>
```

The windows appears as bland plain windows.

What am I missing?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Porting existing WPF to NoesisApp

11 Apr 2023, 14:24

Please find attached a minimal .NET console application that uses NoesisGUI C# nugets.
Basically you have to add the xaml files (and any other resource like images or fonts) as "Embedded Resources", and set the RootNamespace as empty in the project file, so our default resource provider can find the embedded files.

Anyway, we are working on a new project wizard for Visual Studio that will generate project files for C# to help creating new applications.
Attachments
ConsoleApp1.zip
(3.01 KiB) Downloaded 34 times

Who is online

Users browsing this forum: Google [Bot], vinick and 64 guests