As you already seem to know you have to separate the XAML from the code behind, you do that be creating a class like any other normal class and inherit from a Control, like
Window
then in order to alter the appearance and add stuff you have to create a
Style
.
The below article shows you how you can do it.
Building Custom Template-able WPF Controls[
^]