public MainWindow() { InitializeComponent(); DataContext = Grid; // on load, create the gridlines and initialise canvas elements in view model ToggleButton tb = new ToggleButton() { IsChecked = false }; // set default togglestate to false Loaded += delegate { ToggleDynamicGridLines_Click(tb, new RoutedEventArgs()); ToggleStaticGridLines_Click(tb, new RoutedEventArgs()); Grid.ActivateBasisVectors(false); }; // on size change, reinitialise the canvas properties Plane.SizeChanged += delegate { Grid.InitialiseCanvasElement(Plane, new RoutedEventArgs()); }; }