How to locate WPF xaml files to display dialog components in CS-Script?

38 views Asked by At

When I try to display a WPF dialog (summarydialog) in my CS-Script script. I get an error that it cannot locate the xaml files. It's searching here in the Initializecomponent function.

System.Uri resourceLocater = new System.Uri("/CLTD;component/view/summarydialog.xaml", System.UriKind.Relative);

summarydialog.xaml is compiled as "page".

Using dotPeek I see summarydialog.baml (binary version of xaml) located in the CLTD.g.resources/View folder.

How can I tell CS-Script how to locate xaml files? Or perhaps someone knows how to display WPF XAML dialog windows from a CS-Script.

If it's simply the file extension, how does the executable work? Isn't it using the same DLL assembly?

1

There are 1 answers

0
Trey On

You don't need to load the XAML resource. Since it's already compiled, you can just add a reference to the assembly and then create a new instance of the control like normal.

I created a test .NET 5.0 WPF application to test this and built the project.

Here's the cs-script I wrote.

//css_ng csc
//css_winapp
//css_ref WindowsBase
//css_ref PresentationCore
//css_ref PresentationFramework
//css_ref C:\projects\TestWpfApp\bin\Debug\net5.0-windows\TestWpfApp.dll

using System;
using TestWpfApp;

public class Program
{
    public static void Main()
    {
        var window = new MainWindow();
        window.ShowDialog();
    }
}

Then, here's the cli command I ran to run the script:

csws.exe new_script.cs

enter image description here