Changing a converted VO application to WPF

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Changing a converted VO application to WPF

Post by ic2 »

We've, so far successfully, "xported" a VO app to X#. It's a single window program and we want to replace the VO style window with a WPF window. This is were it becomes tricky. We can add a WPF window, getting a .xaml plus the .xaml.prg file. Then we move the code of the start program to the .xaml.prg file and the compiler says:

Method initializecomponent does not have an implementation

To see what we need, we go to a basic X# WPF program, on top of the Solution Explorer we click the icon Show All Files and the files found there and missing in our program are App.config, App.xaml and App.xaml.prg. We add them (and change the Namespace in the App.xaml.prg to the one used in the converted program). We remove the X#/Vulcan style start method and make sure that the program starts as follows:


We add INHERIT Window to the main class name, so it says:

And that's were we get a compiler error:

Error XS0263 Partial declarations of 'WPFScanVenster' must not specify different base classes
The help is not adding much to that (BTW: clicking on the XS0263 link in VS doesn't open anything) - it says Partial declarations of '{0}' must not specify different base classes

A solution wide search does not show anything different than in the basic WPF program. PUBLIC PARTIAL CLASS WPFScanVenster is found another 4 times, in WPFScanVenster.g.prg and WPFScanVenster.g.i.prg, which us duplicated (VS is very good in duplicating) in the Debug and objDebug directory.

How should we proceed from here? Or is there a better way to change a Vo style window based program to a WPF program?

User avatar
Posts: 3655
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Changing a converted VO application to WPF

Post by wriedmann »

Hi Dick,

I would go the other way: build a new WPF application and add the functionalities from your VO program.

Otherwise it could be a nightmare.
I'll do a similar thing with my applications.

But you don't need any XAML file in a WPF program to get it worked.

My WPF programs have the following start() function:

Code: Select all

using System.Diagnostics

function Start( asCmdLine as string[] ) as int
local oApp as App
oApp := App{}
catch oException as System.Exception
Debug.WriteLine( "error in __ENTITY__ " + oException:ToString() ) 
App.HandleException( oException )
end try
return 0
and the App class contains the following code:

Code: Select all

using System
using System.Collections.Generic
using System.Configuration
using System.Windows    
using System.IO

class App inherit Application

protected virtual method OnStartup( e as StartupEventArgs ) as void
local oWindow as AppView

AppDomain.CurrentDomain:UnhandledException += AppDomainUnhandledException
oWindow := AppView{}

protect method CloseApplicationHandler() as void

protected static method AppDomainUnhandledException( Sender as object, e as UnhandledExceptionEventArgs ) as void
HandleException( ( Exception ) e:ExceptionObject )
static method HandleException( oEx as Exception ) as void
System.Diagnostics.Debug.WriteLine( oEx:ToString() )
File.AppendAllText( "c:tempXSError.log", oEx:Message + CRLF + oEx:StackTrace )

end class
Please remember that I'm using a code only (no XAML) approach for my WPF (MVVM) applications.

Wolfgang Riedmann
Meran, South Tyrol, Italy -
Post Reply