Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper offers to remove redundant inheritance from Window class in WPF

In WPF projects Resharper offers to remove inheritance from Window class as redundant:

using System.Windows;

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

It is become possible to remove even using System.Windows;.

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

Why actually he offer this and why without that inheritance everything works fine? As I read in books of WPF any window anyway should be inherited...

like image 858
kyrylomyr Avatar asked Dec 09 '22 09:12

kyrylomyr


2 Answers

XAML code-behind files are partial classes. The code generated by the compiler from the XAML file also includes the Window derivation so the one in the code-behind is redundant.

like image 125
John Bowen Avatar answered Jan 21 '23 11:01

John Bowen


Your MainWindow class (like most designer-generated classes) is a partial class. This means that the implementation for your class can be broken up into multiple files, as long as they're all within the same assembly.

Because the designer-generated file for MainWindow also contains : Window, it's not necessary to include it in any other files.

like image 37
Adam Robinson Avatar answered Jan 21 '23 11:01

Adam Robinson