0

I want to create a Window in WPF while the application is running. WHY? Its part of my modell driven design. It is not the window only. I want to load a XAML file and the window class behind the XAML. What i know is how to create a simple class with System.CodeDom.Compiler. But on a window i need the "MyWindow.i.g.cs" file, the "class MyWindow : Window" and my XAML file. What i want? I want set up databindings on the dynamic window in the constructor.

A little bit information behind my project: I got a generator that generates code and xaml files from a modell. I got a Database that is holding the c# code and xaml file in combination for each Window. Now i got an application that load the windows by names from the database, compile and show it. My Problem here is the declaration of my xaml Member (this.txt_Maintype). The compiler says "this is no member of Mainwindow".

public partial class MainWindow : Window
{

    public MainWindow()
    {
        TypeClass content;
        content = new TypeClass();
        this.DataContext = content;
        this.txt_Maintype.DataContext = content.Property_ident_deklaration;
        this.txt_template.DataContext = content.Property_ident_deklaration;
        this.txt_Extentiontype.DataContext = content.Property_ident_deklaration;
    }
}

And the Method InitializeComponent() is not defined. I know there is an *.i.g.cs file in visual studio that implements the InitializeComponent. So how to merge all these files to compile it?

Thanks for help

I hope you understand what i want. It is difficult to explain it.

1 Answer 1

1

I don't think what you are trying to do is possible. You need to use the Microsoft Build Engine (MSBuild) or Visual Studio to be able to build a WPF application that contains XAML markup.

This is stated in the documentation on MSDN: https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/building-a-wpf-application-wpf.

A WPF application can be compiled in the following ways:

-Command-line. The application must contain only code (no XAML) and an application definition file. For more information, see Command-line Building With csc.exe or Building from the Command Line (Visual Basic).

-Microsoft Build Engine (MSBuild). In addition to the code and XAML files, the application must contain an MSBuild project file. For more information, see "MSBuild".

-Visual Studio. Visual Studio is an integrated development environment that compiles WPF applications with MSBuild and includes a visual designer for creating UI. For more information, see Application Development in Visual Studio and WPF Designer.

You could load a XAML string dynamically using the XamlReader.Parse method though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.