/// <summary> /// Add table to canvas /// </summary> /// <param name="viewModel">Viewmodel of table</param> private void AddTableElement(TableViewModel viewModel) { var content = new TableContent(viewModel); var owner = Window.GetWindow(this) as MainWindow; content.AddNewRow += owner.AddNewRowHandler; content.EditSelectedRow += owner.EditRowHandler; content.RenameTable += owner.RenameTableHandler; content.RemoveSelectedRow += owner.RemoveRowHandler; content.DropTable += owner.DropTableHandler; content.UpdatePrimaryKeyConstraint += owner.UpdatePrimaryKeyConstraintHandler; RoutedEventHandler loadedEventHandler = null; loadedEventHandler = (sender, args) => { MeasureToFit(content); DesignerCanvas.SetZIndex(content, DesignerCanvas.TableUnselectedZIndex); DesignerCanvas.SetTop(content, viewModel.Top); DesignerCanvas.SetLeft(content, viewModel.Left); content.Height = content.ActualHeight + 30; content.Width = content.ActualWidth + 30; viewModel.Height = content.Height; viewModel.Width = content.Width; viewModel.OnTableLoaded(content); content.Loaded -= loadedEventHandler; }; content.Loaded += loadedEventHandler; ModelDesignerCanvas.Children.Add(content); }
/// <summary> /// Add new label to canvas /// </summary> /// <param name="viewModel">Label viewmodel</param> private void AddLabelElement(LabelViewModel viewModel) { var content = new LabelContent(viewModel); RoutedEventHandler loadedEventHandler = null; loadedEventHandler = (sender, args) => { MeasureToFit(content); DesignerCanvas.SetZIndex(content, DesignerCanvas.LabelUnselectedZIndex); DesignerCanvas.SetTop(content, viewModel.Top); DesignerCanvas.SetLeft(content, viewModel.Left); content.Height = content.ActualHeight + 30; content.Width = content.ActualWidth + 30; viewModel.Height = content.Height; viewModel.Width = content.Width; content.Loaded -= loadedEventHandler; }; content.Loaded += loadedEventHandler; ModelDesignerCanvas.Children.Add(content); }