WPF: How to replace the default MainWindow.xaml.cs and MainWindow.xaml files?

703 views Asked by At

This is a common problem:

I find an XAML pair on the Internet, one which does exactly what I need. I was able to "Add Existing Item" so both pairs are recognized.

To complicate matters further, the original file's signature looks as customary:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

but the newcomer (rectangleexample) has a different signature:

public partial class RectangleExample : Page
{
    public RectangleExample()
    {
        InitializeComponent();
    }
}

I had to comment out the second InitializeComponent() because it is not found.

Is there a straightforward way (ie, without complicated surgery) to accomplish this?

Update:

I did a full copy (of the newcomer file) on the existent XAML. I removed the old MainWindow pair and renamed the new ones. This is the only remaining problem:

The name InitializeComponent does not exist in the current context

I tried to find a "Add Existent Item", looking for a XAML pair, but such option is not there.

1

There are 1 answers

0
Felice Pollano On

Look for Initialize component trough all the files in the solution, it is defined in a partial class, so you have to rename that class as well.