private void CreateTextPostAt(Point position, double width, double height, DateTime creationTime, string postFile, Color background)
        {
            DesignerItem newItem = null;

            UserControl content = new PostEditor();

            content.Margin = new Thickness(2, 10, 2, 2);

            if (content != null)
            {
                newItem = new DesignerItem();
                newItem.CreationTime = creationTime;

                newItem.Content = content;
                ((PostEditor)content).BackgroundColor = background;
                ((PostEditor)content).SetCreationTime(newItem.CreationTime);
                ((PostEditor)content).LoadPost(postFile);

                newItem.Width = width;
                //newItem.Height = height;

                DesignerCanvas.SetLeft(newItem, position.X);
                DesignerCanvas.SetTop(newItem, position.Y);
                this.Children.Add(newItem);

                this.DeselectAll();
                newItem.IsSelected = true;

                newItem.SaveMethod = ((PostEditor)content).SavePost;
            }
        }
        public void CreateTextPostAt(Point position, Color postColor)
        {
            DesignerItem newItem = null;

            UserControl content = new PostEditor();
            content.Margin = new Thickness(2, 10, 2, 2);

            if (content != null)
            {
                newItem = new DesignerItem();
                newItem.Content = content;
                ((PostEditor)content).SetCreationTime(newItem.CreationTime);
                ((PostEditor)content).BackgroundColor = postColor;

                if (content.MinHeight != 0 && content.MinWidth != 0)
                {
                    newItem.Width = content.MinWidth * 2; ;
                    //newItem.Height = content.MinHeight * 2;
                }
                else
                {
                    newItem.Width = 250;
                    //newItem.MinHeight = 285;
                }
                DesignerCanvas.SetLeft(newItem, position.X); // Math.Max(0, position.X - newItem.Width / 2));
                DesignerCanvas.SetTop(newItem, position.Y); // Math.Max(0, position.Y - newItem.Height / 2));
                this.Children.Add(newItem);

                this.DeselectAll();
                newItem.IsSelected = true;

                newItem.SaveMethod = ((PostEditor)content).SavePost;
            }
        }
        public void CreateTextPostAt(Point position, Color postColor)
        {
            DesignerItem newItem = null;

            UserControl content = new PostEditor();

            content.Margin = new Thickness(2, 10, 2, 2);

            if (content != null)
            {
                newItem         = new DesignerItem();
                newItem.Content = content;
                ((PostEditor)content).SetCreationTime(newItem.CreationTime);
                ((PostEditor)content).BackgroundColor = postColor;

                if (content.MinHeight != 0 && content.MinWidth != 0)
                {
                    newItem.Width = content.MinWidth * 2;;
                    //newItem.Height = content.MinHeight * 2;
                }
                else
                {
                    newItem.Width = 250;
                    //newItem.MinHeight = 285;
                }
                DesignerCanvas.SetLeft(newItem, position.X); // Math.Max(0, position.X - newItem.Width / 2));
                DesignerCanvas.SetTop(newItem, position.Y);  // Math.Max(0, position.Y - newItem.Height / 2));
                this.Children.Add(newItem);

                this.DeselectAll();
                newItem.IsSelected = true;

                newItem.SaveMethod = ((PostEditor)content).SavePost;
            }
        }
Example #4
0
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);
            DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas;

            e.Handled = false;

            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    this.IsSelected = !this.IsSelected;
                }
                else
                {
                    if (e.ChangedButton == MouseButton.Right)
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        if (!this.IsSelected)
                        {
                            designer.DeselectAll();
                            this.IsSelected = true;
                            PostEditor content = this.Content as PostEditor;
                            if (content != null)
                            {
                                content.SetFocus();
                            }
                        }
                    }
                }
            }
        }
        private void OnButtonClicked(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Debug.Write("button clicked");
            PostEditor       source = e.Source as PostEditor;
            DependencyObject parent = VisualTreeHelper.GetParent(source);

            this.MyDesignerCanvas.DeletePost(source);
        }
        public void DeletePost(PostEditor postEditor)
        {
            DesignerItem toBeDeleted = null;

            foreach (DesignerItem item in this.Children.OfType <DesignerItem>())
            {
                if (item.Content == postEditor)
                {
                    toBeDeleted = item;
                }
            }

            this.Children.Remove(toBeDeleted);
        }
        private void CreateTextPostAt(Point position, double width, double height, DateTime creationTime, string postFile, Color background)
        {
            DesignerItem newItem = null;

            UserControl content = new PostEditor();

            content.Margin = new Thickness(2, 10, 2, 2);

            if (content != null)
            {
                newItem = new DesignerItem();
                newItem.CreationTime = creationTime;

                newItem.Content = content;
                ((PostEditor)content).BackgroundColor = background;
                ((PostEditor)content).SetCreationTime(newItem.CreationTime);
                ((PostEditor)content).LoadPost(postFile);

                newItem.Width = width;
                //newItem.Height = height;

                DesignerCanvas.SetLeft(newItem, position.X);
                DesignerCanvas.SetTop(newItem, position.Y);
                this.Children.Add(newItem);

                this.DeselectAll();
                newItem.IsSelected = true;

                newItem.SaveMethod = ((PostEditor)content).SavePost;
            }
        }
        public void DeletePost(PostEditor postEditor)
        {
            DesignerItem toBeDeleted = null;
            foreach(DesignerItem item in this.Children.OfType<DesignerItem>()){
                if (item.Content == postEditor)
                {
                    toBeDeleted = item;
                }
            }

            this.Children.Remove(toBeDeleted);
        }