I solved this on my own by creating the template in the constructor of my control.. It was not easy but I did it..
Here the code I wrote.
this.DataContext = this;
var template = new ControlTemplate();
var mainGrid = new FrameworkElementFactory(typeof(Grid));
var borderTemplate = new FrameworkElementFactory(typeof(Border));
borderTemplate.SetValue(Border.BorderBrushProperty, Brushes.Gray);
borderTemplate.SetValue(Border.BorderThicknessProperty, new Thickness(3));
borderTemplate.SetValue(Border.BackgroundProperty, Brushes.WhiteSmoke);
borderTemplate.SetBinding(Border.CornerRadiusProperty, new Binding("CornerRadius"));
borderTemplate.SetValue(Border.EffectProperty, new DropShadowEffect() { Color = Colors.Black, ShadowDepth = 7.5, Direction = 315 });
var gridTemplate = new FrameworkElementFactory(typeof(Grid));
gridTemplate.SetValue(Grid.MarginProperty, new Thickness(3));
var titleColTemplate = new FrameworkElementFactory(typeof(ColumnDefinition));
var minimizeColTemplate = new FrameworkElementFactory(typeof(ColumnDefinition));
minimizeColTemplate.SetValue(ColumnDefinition.WidthProperty, new GridLength(35));
var maximizeColTemplate = new FrameworkElementFactory(typeof(ColumnDefinition));
maximizeColTemplate.SetValue(ColumnDefinition.WidthProperty, new GridLength(35));
var closeColTemplate = new FrameworkElementFactory(typeof(ColumnDefinition));
closeColTemplate.SetValue(ColumnDefinition.WidthProperty, new GridLength(35));
var titleRowTemplate = new FrameworkElementFactory(typeof(RowDefinition));
titleRowTemplate.SetValue(RowDefinition.HeightProperty, new GridLength(20));
var contentRowTemplate = new FrameworkElementFactory(typeof(RowDefinition));
var titleTemplate = new FrameworkElementFactory(typeof(TextBlock));
titleTemplate.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
titleTemplate.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
titleTemplate.SetValue(TextBlock.FontStyleProperty, FontStyles.Italic);
titleTemplate.SetBinding(TextBlock.TextProperty, new Binding("Title"));
titleTemplate.SetValue(TextBlock.MarginProperty, new Thickness(10, 0, 0, 0));
var minimizeTemplate = new FrameworkElementFactory(typeof(Button));
minimizeTemplate.SetValue(Button.MarginProperty, new Thickness(1));
minimizeTemplate.SetValue(Button.FontWeightProperty, FontWeights.ExtraBold);
minimizeTemplate.SetValue(Button.FontFamilyProperty, new FontFamily("Arial Black"));
minimizeTemplate.SetValue(Grid.ColumnProperty, 1);
minimizeTemplate.SetValue(Button.ContentProperty, "_");
minimizeTemplate.AddHandler(Button.ClickEvent, new RoutedEventHandler(this.minimize_Click));
var maximizeTemplate = new FrameworkElementFactory(typeof(Button));
maximizeTemplate.SetValue(Button.MarginProperty, new Thickness(1));
maximizeTemplate.SetValue(Button.FontWeightProperty, FontWeights.ExtraBold);
maximizeTemplate.SetValue(Button.FontFamilyProperty, new FontFamily("Arial Black"));
maximizeTemplate.SetValue(Grid.ColumnProperty, 2);
maximizeTemplate.SetValue(Button.ContentProperty, "☐");
maximizeTemplate.AddHandler(Button.ClickEvent, new RoutedEventHandler(this.maximize_Click));
var closeTemplate = new FrameworkElementFactory(typeof(Button));
closeTemplate.SetValue(Button.MarginProperty, new Thickness(1));
closeTemplate.SetValue(Button.FontWeightProperty, FontWeights.ExtraBold);
closeTemplate.SetValue(Button.FontFamilyProperty, new FontFamily("Arial Black"));
closeTemplate.SetValue(Grid.ColumnProperty, 3);
closeTemplate.SetValue(Button.ContentProperty, "✘");
closeTemplate.SetValue(Button.ForegroundProperty, Brushes.Red);
closeTemplate.AddHandler(Button.ClickEvent, new RoutedEventHandler(this.close_Click));
var contentTemplate = new FrameworkElementFactory(typeof(ContentControl));
contentTemplate.SetValue(Grid.RowProperty, 1);
contentTemplate.SetValue(Grid.ColumnSpanProperty, 4);
contentTemplate.SetValue(ContentControl.MarginProperty, new Thickness(5));
contentTemplate.SetBinding(ContentControl.ContentProperty, new Binding("Content"));
gridTemplate.AppendChild(titleColTemplate);
gridTemplate.AppendChild(minimizeColTemplate);
gridTemplate.AppendChild(maximizeColTemplate);
gridTemplate.AppendChild(closeColTemplate);
gridTemplate.AppendChild(titleRowTemplate);
gridTemplate.AppendChild(contentRowTemplate);
gridTemplate.AppendChild(titleTemplate);
gridTemplate.AppendChild(minimizeTemplate);
gridTemplate.AppendChild(maximizeTemplate);
gridTemplate.AppendChild(closeTemplate);
gridTemplate.AppendChild(contentTemplate);
mainGrid.AppendChild(borderTemplate);
mainGrid.AppendChild(gridTemplate);
template.VisualTree = mainGrid;
this.Template = template;
Thank Ron Beyer for your kind help :)