WPF: Partial class

This entry is part 3 of 54 in the series Learn WPF

You can see from the first empty application that there are 2 files, MainWindow.xaml and MainWindow.xaml.cs that are created by Visual Studio.


<Window x:Class="Wpf.MainWindow"
        Title="MainWindow" Height="350" Width="525">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wpf
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

Notice the relationship between the 2 files.  In line 21, we say that MainWindow is a partial class.  This is because it needs to combine with the MainWindow in the xaml file (line 4), to form a full class declaration.

In line 4 in MainWindow.xaml, we have some declarations related to the title of the window and the size of the window.  We can make some changes to them to change the characteristics of the window.

We can also add new characteristics such as adding a ResizeMode.  Add the following property and you will find that the window is now fixed.




Series Navigation<< WPF: Creating an application
WPF: Controls >>