简体   繁体   中英

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

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.

在解决方案中的所有文件中查找“初始化组件”,它是在局部类中定义的,因此您也必须重命名该类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM