Issues with creating a new WPF X# program

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

Issues with creating a new WPF X# program

Post by ic2 »

I've got 2 issues with creating a new WPF X# program.

First is probably one of the many dreadful VS issues, maybe someone knows how to prevent that. When I right click Add, New project, WPF Application (X#), the suggested project name is WpfApplication1. I change that, click Create, the namespace is now the name I've chosen but the class name looks as follows:

PUBLIC PARTIAL CLASS WPFWindow1 INHERIT Window

How can I prevent the class to be called WPFWindow1?

Now you would probably say, just rename all occurrences of WPFWindow1 with YourName.

I did. Then the program doesn't start anymore (without a visible error). In debug mode however I get:

System.IO.IOException: 'Cannot locate resource 'yourname.xaml'.'

So I want to either prevent having the wrong class name to start with or if that is not possible, rename my class and prevent or solve this stupid VS error. How can I do that?

Another issue is that when I select, in WPF XAML, Click="MyMethodName" and press F12 (goto definition) this does not work in X# (it does in C#). You get an errorbox Cannot navigate to definition.

In C# it would create the event MyMethodName with all parameters. It will almost sure be totally mislocated in the code, which is a logical result of the deficient VS design, but at least I get my method to start with.

Also when the method is created F12/Goto definition on the Click event in XAML won't work in X#.

Is that something which can be fixed?

Dick
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Issues with creating a new WPF X# program

Post by Chris »

Hi Dick,

From what I see, c# using a different naming scheme for the window that gets autocreated, and names it "MainWindow", which I guess is much more appropriate than the "WPFWindow1" that X# generates. I will add log this is as a request for Robert to change this, as this would already make changing the name less necessary. Still, it is possible to change the name and do it without breaking everything in the project, but I will let the WPF gurus to explain how to do it.

About picking a totally custom name for the window in advance, when creating the new project, that would involve specifying this name in some extra dialog or something, and I'm not aware if VS supports something like that (XIDE does :)), so I am not sure if it;s possible to do it somehow.

The problem with Goto Definition in the XAML is I guess soemthing that's not implemented yet in X#, will log this as well, thanks.

.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Issues with creating a new WPF X# program

Post by Chris »

Hi Dick,

Actually, renaming a WPF window is very easy! All you need is to go to the solution explorer and rename the main tree item for the window (WPFWindow1.xaml) to the new names, and then everything else happens automatically and the project builds with no errors. I just tried it, it does work also with X#.

Edit: Oops, sorry...It builds, but it does not run (as you said :)). Will log a report...
Edit2: Oops again, I tried also with c# and it also has the same problem!!! OK, I will not make a comment about VS or WPF (or open a report), I will let the guys who know explain how to change the name properly...
.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Issues with creating a new WPF X# program

Post by ic2 »

Hello Chris,
Chris wrote:Hi Dick,

About picking a totally custom name for the window in advance, when creating the new project, that would involve specifying this name in some extra dialog or something, and I'm not aware if VS supports something like that (XIDE does :)), so I am not sure if it;s possible to do it somehow..
I don't think it's possible in VS but hey, Microsoft doesn't employ developers from your caliber so they won't even come to the idea that this is something that should have been implemented :unsure:

Dick
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Issues with creating a new WPF X# program

Post by robert »

Dick,
The App.Xaml fole contains the name of the first windows that has to be shown:

<

Code: Select all

Application x:Class="$safeprojectname$.$safeitemname$"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="WPFWindow1.xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>

You need to change the name there to match your new mainwindow name.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Issues with creating a new WPF X# program

Post by ic2 »

I solved it as follows. In an external program UltraFileSearch I searched for all occurrences of WPFWindow1 and replaced it in a texteditor by my class name. E.g.:

<Window x:Class= (namespace.class) in the .xaml window
StartupUri=... in the app.xaml
plus in a couple of obscure programs like D:XSharpProjectsMyProgramobjDebugApp.g.i.prg and App.g.prg.

One program is still called WPFWindow1.g.i.prg but that seems no real problem.

Did I tell you I hate Visual Studio?

I found some remarks leading me into this direction on Stackoverflow NINE years ago.
None of those low brain VS "engineers" has cared to fix a serious bug during a simple action to rename a class.

I keep wondering why Microsoft hasn't been declared bankrupt many years ago.

Dick
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Issues with creating a new WPF X# program

Post by Chris »

Well, they are too big and also too many people (like us) depend on them unfortunately, so...
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Issues with creating a new WPF X# program

Post by robert »

Dick,
ic2 wrote: <Window x:Class= (namespace.class) in the .xaml window
StartupUri=... in the app.xaml
plus in a couple of obscure programs like D:XSharpProjectsMyProgramobjDebugApp.g.i.prg and App.g.prg.
One program is still called WPFWindow1.g.i.prg but that seems no real problem.
Those .g.prg and .g.i.prg inside the obj folder are generated by the build system from the xaml files. They can be safely deleted. I think the "G" is for "Generated" and the "I" is for "Intellisense".

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Issues with creating a new WPF X# program

Post by ic2 »

Thank you Robert, I added this to my notes in the chapter "How to solve problems which wouldn't exist if Microsoft were an actually capable software company" :angry: .

DIck
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Issues with creating a new WPF X# program

Post by TerryB1 »

Hi Dick

There are a number of places in a program where you have to tackle two actions in concert and this is one of them.

Essentially what you see and build using SloutionExplorer is a directory structure. What you code in your program is a set of namespaces. So you have Directory linkages and Code linkages which are independent but must marry up or you'll end up in a mess.

This is easier to show diagrammatically so I have attached a JPEG which I hope helps.

Terry
Attachments
Namespace Relationship.jpg
Namespace Relationship.jpg (19.17 KiB) Viewed 778 times
Post Reply