public MainWindow()
        {
            InitializeComponent();
            // initialize the singleton.
            ins ??= this;
            // make te style button a toggle for the shape buttons.
            buttonStyle.Click += (a, b) => stylesDisplay.Visibility = stylesDisplay.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
            // initialize the clear button.
            buttonClear.Click += (a, b) => CommandManager.GetInstance().InvokeCommand(new ClearCommand());
            // set the current newState to None.
            SwitchState(States.None);
            // assign the stack panel from the hierarchy.
            Hierarchy.GetInstance().SetStackPanel(selectionDisplay);
            // Initialize the buttons
            InitializeStyleButtons();
            // bind the undo and redo actions to their corresponding  buttons
            buttonUndo.Click += (a, b) => CommandManager.GetInstance().Undo();
            buttonRedo.Click += (a, b) => CommandManager.GetInstance().Redo();
            // als bind it to the control+z and contrl+r keys
            KeyDown += (a, b) =>
            {
                switch (b.Key)
                {
                case Key.Z: if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        CommandManager.GetInstance().Undo();
                    }
                    break;

                case Key.R: if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        CommandManager.GetInstance().Redo();
                    }
                    break;

                case Key.M: CommandManager.GetInstance().InvokeCommand(new SwitchGroupCommand(Hierarchy.GetInstance().GetTopGroup()));  break;

                case Key.J:

                    if (Keyboard.IsKeyDown(Key.LeftCtrl) && Selection.GetInstance().GetChildren().Count > 0)
                    {
                        CommandManager.GetInstance().InvokeCommand(new MergeCommand());
                    }
                    break;
                }
            };
            // go to back to Draw newState when rmb is pressed.
            MouseRightButtonDown += (a, b) =>
            {
                if (state == States.Select)
                {
                    new ChangeShapeStyleCommand(styleIndex).Execute();

                    Selection.GetInstance().Clear();

                    Hierarchy.GetInstance().DeselectAllButtons();
                }
            };
            // click the first shape button
            ((Button)stylesDisplay.Children[0]).RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent));
        }