public void addToDragList() { MouseDragElementBehavior dragBehavior = new MouseDragElementBehavior(); dragBehavior.Attach(this); dragBehavior.Dragging += dragBehavior_Dragging; MouseDragElementBehavior dragBehaviorConnectorFront = new MouseDragElementBehavior(); dragBehaviorConnectorFront.Attach(FrontConnector); dragBehaviorConnectorFront.Dragging += dragBehaviorConnectorFront_Dragging; MouseDragElementBehavior dragBehaviorConnectorTail = new MouseDragElementBehavior(); dragBehaviorConnectorTail.Attach(TailConnector); dragBehaviorConnectorTail.Dragging += dragBehaviorConnectorTail_Dragging; }
private void addToDragList(Shape renderShape, Point pt) { MouseDragElementBehavior dragBehaviorEllipse = new MouseDragElementBehavior(); dragBehaviorEllipse.Attach(renderShape); //TextBlock lable = new TextBlock { Text = "X = " + pt.X + ", Y = " + pt.Y }; //lable.RenderTransform = new TranslateTransform(); //Canvas.SetLeft(lable, pt.X + NODE_DIMENSION + 3); //Canvas.SetTop(lable, pt.Y + (NODE_DIMENSION / 2 - 5)); //DisplayArea.Children.Add(lable); //renderShape.Tag = lable; // attach to Ellipse _label.Text = getLabelText(pt); dragBehaviorEllipse.Dragging += dragBehaviorEllipse_Dragging; dragBehaviorEllipse.DragFinished += dragBehaviorEllipse_DragFinished;; }
private async void InitMainMenu() { #region 初始化属性 var mainMenuInfo = _userConfigution.ImageSetting.MainMenuInfo; var animatedGif = await GetMainMenuIcon(); _mainMenu = new UserControl { Content = animatedGif, Width = mainMenuInfo.Width, Height = mainMenuInfo.Height, ToolTip = "EasyImage主菜单", Cursor = Cursors.SizeAll, }; var transformGroup = new TransformGroup(); transformGroup.Children.Add(new ScaleTransform(1, 1)); transformGroup.Children.Add(new RotateTransform(0)); transformGroup.Children.Add(new TranslateTransform(mainMenuInfo.TranslateX, mainMenuInfo.TranslateY)); _mainMenu.RenderTransform = transformGroup; var dragBehavior = new MouseDragElementBehavior <UserControl> { MoveableRange = new Rect(0, 0, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight), }; dragBehavior.Attach(_mainMenu); _autoHideBehavior = new AutoHideElementBehavior { AutoHideFactor = _userConfigution.WindowState.ImageWindowState.AutoHideFactor, }; _autoHideBehavior.Attach(_mainMenu); #endregion #region 添加上下文菜单 var contextMenu = new ContextMenu(); var item = new MenuItem { Header = "新建", Tag = "New" }; #region 二级菜单 var subItem = new MenuItem { Header = "矩形", Tag = "Square" }; subItem.Click += AddImageFromInternal; item.Items.Add(subItem); subItem = new MenuItem { Header = "圆形", Tag = "Circle" }; subItem.Click += AddImageFromInternal; item.Items.Add(subItem); subItem = new MenuItem { Header = "三角形", Tag = "Triangle" }; subItem.Click += AddImageFromInternal; item.Items.Add(subItem); subItem = new MenuItem { Header = "五角星", Tag = "FiveStar" }; subItem.Click += AddImageFromInternal; item.Items.Add(subItem); subItem = new MenuItem { Header = "圆环", Tag = "Torus" }; subItem.Click += AddImageFromInternal; item.Items.Add(subItem); #endregion contextMenu.Items.Add(item); item = new MenuItem { Header = "打开", Tag = "Open" }; item.Click += LoadEasyImageFromFile; contextMenu.Items.Add(item); item = new MenuItem { Header = "添加", Tag = "Add" }; item.Click += AddImagesFromFile; contextMenu.Items.Add(item); item = new MenuItem { Header = "保存", Tag = "Save" }; item.Click += SaveEasyImageToFile; contextMenu.Items.Add(item); item = new MenuItem { Header = "另保存", Tag = "SaveAs" }; item.Click += SaveAsEasyImageToFile; contextMenu.Items.Add(item); item = new MenuItem { Header = "粘贴", Tag = "Paste" }; item.Click += PasteImagesFromClipboard; contextMenu.Items.Add(item); item = new MenuItem { Header = "设置", Tag = "Setting" }; item.Click += SettingWindow; contextMenu.Items.Add(item); item = new MenuItem { Header = "收藏夹", Tag = "Favorites" }; item.Click += (sender, e) => { _imageFavoritesWindow.ShowWindow(); }; contextMenu.Items.Add(item); contextMenu.Items.Add(new Separator());//分割线 item = new MenuItem { Header = "退出", Tag = "Exit" }; item.Click += (sender, args) => { Close(); }; contextMenu.Items.Add(item); _mainMenu.ContextMenu = contextMenu; #endregion #region 添加事件 _mainMenu.MouseDown += MainMenu_MouseDown; _mainMenu.ContextMenuOpening += MainMenu_ContextMenuOpening; #endregion MainCanvas.Children.Add(_mainMenu); }
private void SetMyLayerBase(Window owner, object content, string title, MyLayerOptions options, bool isDiaglog, Action action) { if (options == null) { options = MYUI.DefaultAyLayerOptions; } _options = options; this.Title = title ?? ""; //this.Topmost = true; //this.ShowInTaskbar = true; //if (owner != null) //{ // Owner = owner; //} Owner = owner ?? Application.Current.MainWindow; //userPresenter.Content = content; var fram = content as FrameworkElement; if (fram != null) { userPresenter.Width = fram.Width; userPresenter.Height = fram.Height; } if (options.CanDrag) { MouseDragElementBehavior m = new MouseDragElementBehavior(); m.Attach(body); //body.MouseMove += new MouseEventHandler(Element_MouseMove); //body.MouseLeftButtonDown += new MouseButtonEventHandler(Element_MouseLeftButtonDown); //body.MouseLeftButtonUp += new MouseButtonEventHandler(Element_MouseLeftButtonUp); } if (options.IsContainsTitleBar) { d.Height = Extensiones.ToGridLength("42.00"); Border b = new Border(); if (options.LayerCornerRadius.HasValue) { b.Margin = new Thickness(-1, -1, -1, 0); b.CornerRadius = new CornerRadius(options.LayerCornerRadius.Value.TopLeft, options.LayerCornerRadius.Value.TopRight, 0, 0); } b.HorizontalAlignment = HorizontalAlignment.Stretch; b.VerticalAlignment = VerticalAlignment.Stretch; //b.SetResourceReference(Border.BackgroundProperty, Colors.CadetBlue); b.Background = SolidColorBrushConverter.From16JinZhi("#F0F1F2"); Grid g = new Grid(); if (!string.IsNullOrWhiteSpace(title)) { TextBlock tb = new TextBlock(); tb.Width = 200; tb.VerticalAlignment = VerticalAlignment.Center; tb.HorizontalAlignment = HorizontalAlignment.Left; tb.Margin = new Thickness(10, 0, 0, 0); tb.TextWrapping = TextWrapping.NoWrap; tb.FontSize = 14; tb.TextTrimming = TextTrimming.CharacterEllipsis; //tb.Foreground = SolidColorBrushConverter.From16JinZhi("#99FFFFFF"); Binding binding = new Binding { Path = new PropertyPath("Title"), Source = this, Mode = BindingMode.TwoWay }; tb.SetBinding(TextBlock.TextProperty, binding); g.Children.Add(tb); } MyImageButton ab = new MyImageButton(); ab.RenderMode = MyImageButtonMode.HorizonFour; ab.SnapsToDevicePixels = true; ab.Margin = new Thickness(0, 0, 10, 0); ab.Height = ab.Width = 26; ab.VerticalAlignment = VerticalAlignment.Center; ab.HorizontalAlignment = HorizontalAlignment.Right; ab.Padding = new Thickness(0); ab.Icon = new BitmapImage(new Uri("pack://application:,,,/MyWPFUI;component/Resources/Images/closebtn.png")); ab.Click += closewindow_Click; ab.VerticalContentAlignment = VerticalAlignment.Center; ab.HorizontalContentAlignment = HorizontalAlignment.Center; //ab.Foreground = SolidColorBrushConverter.From16JinZhi("#99FFFFFF"); //ab.Content = "关闭"; g.Children.Add(ab); b.Child = g; bodyConent.Children.Add(b); } Console.WriteLine("开始触发options.MaskBrush"); if (options.MaskBrush.IsNotNull()) { layoutMain.Background = options.MaskBrush; } if (isDiaglog) { if (options.MaskBrush.IsNull()) { layoutMain.Background = SolidColorBrushConverter.From16JinZhi("#05FFFFFF"); } layoutMain.MouseLeftButtonDown += LayoutMain_MouseLeftButtonDown; } Console.WriteLine("开始触发options.IsShowLayerBorder"); if (options.IsShowLayerBorder) { body.SetResourceReference(Border.BorderBrushProperty, "Ay.Brush14"); if (options.LayerBorderThickness.HasValue) { body.BorderThickness = options.LayerBorderThickness.Value; } else { body.BorderThickness = new Thickness(1); } } Console.WriteLine("开始触发options.LayerCornerRadius"); if (options.LayerCornerRadius.HasValue) { body.CornerRadius = options.LayerCornerRadius.Value; } options.LayerBackground.Freeze(); body.Background = options.LayerBackground; Console.WriteLine("开始触发options.ShowAnimateIndex"); if (options.ShowAnimateIndex == 0) { ShowShadow(options); body.Visibility = Visibility.Visible; this.ContentRendered += (e, f) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 1) { var sc = new MyAniScale(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.ScaleXFrom = 0; sc.ScaleYFrom = 0; sc.ScaleXTo = 1; sc.ScaleYTo = 1; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 2) { var sc = new MyAniSlideInDown(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.FromDistance = -4000; sc.OpacityNeed = false; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 3) { var sc = new MyAniSlideInUp(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.FromDistance = 4000; sc.OpacityNeed = false; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 4) { var sc = new MyAniSlideInLeft(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.FromDistance = -4000; sc.OpacityNeed = false; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 5) { var sc = new MyAniSlideInRight(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.FromDistance = 4000; sc.OpacityNeed = false; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 6) { var sc = new MyAniBounceInDown(body, () => { ShowShadow(options); }); sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 7) { var sc = new MyAniBounceInUp(body, () => { ShowShadow(options); }); sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 8) { var sc = new MyAniBounceInLeft(body, () => { ShowShadow(options); }); sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 9) { var sc = new MyAniBounceInRight(body, () => { ShowShadow(options); }); sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 10) { var sc = new MyAniRotateIn(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.EasingFunction = new System.Windows.Media.Animation.CubicEase { EasingMode = EasingMode.EaseOut }; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } else if (options.ShowAnimateIndex == 11) { var sc = new MyAniBounceIn(body, () => { ShowShadow(options); }); sc.AnimateSpeed = 750; sc.Animate().End(); sc.story.Completed += (c, d) => { userPresenter.Content = content; if (action != null) { MyTime.SetTimeout(20, action); } }; } //else if (options.ShowAnimateIndex == 12) //{ // var sc = new MyAniSlideOutDown(body, () => // { // ShowShadow(options); // }); // sc.AnimateSpeed = 750; // sc.Animate().End(); // sc.story.Completed += (c, d) => // { // userPresenter.Content = content; // if (action != null) // MyTime.SetTimeout(20, action); // }; //} //else if (options.ShowAnimateIndex == 13) //{ // var sc = new MyAniSlideOutRight(body, () => // { // ShowShadow(options); // }); // sc.AnimateSpeed = 750; // sc.Animate().End(); // sc.story.Completed += (c, d) => // { // userPresenter.Content = content; // if (action != null) // MyTime.SetTimeout(20, action); // }; //} //else if (options.ShowAnimateIndex == 14) //{ // var sc = new MyAniSlideOutUp(body, () => // { // ShowShadow(options); // }); // sc.AnimateSpeed = 750; // sc.Animate().End(); // sc.story.Completed += (c, d) => // { // userPresenter.Content = content; // if (action != null) // MyTime.SetTimeout(20, action); // }; //} //else if (options.ShowAnimateIndex == 15) //{ // var sc = new MyAniSlideOutLeft(body, () => // { // ShowShadow(options); // }); // sc.AnimateSpeed = 750; // sc.Animate().End(); // sc.story.Completed += (c, d) => // { // userPresenter.Content = content; // if (action != null) // MyTime.SetTimeout(20, action); // }; //} }