public static UIElement CreateElement(SaveItemInfo info) { Canvas canvas; ToolboxItem item = null; double x, y; item = ToolboxItem.GetToolBoxItemPreview(info); if (item.Content is jg.Editor.Library.Control.ControlMediaElement) { ((jg.Editor.Library.Control.ControlMediaElement)item.Content).ScaleChanged += PageStage_ScaleChanged; } item.DataContext = info; x = Canvas.GetLeft(item); y = Canvas.GetTop(item); if (item.AssetType != AssetType.HTML5) { item.MouseEnter += (sender, e) => { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (info.assetActionInfo == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseEnter) { return; } AssetAction(info, selectedItems, x, y); }; ShowMaxBox smb = item.Content as ShowMaxBox; if (smb != null) { smb.eventShowAsset += item_showAsset; } item.MouseLeave += (sender, e) => { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (info.assetActionInfo == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseEnter) { return; } UnAssetAction(info, selectedItems, x, y); }; item.MouseLeftButtonUp += (sender, e) => { try { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } switch (info.assetActionInfo.AssetAction) { case enumAssetAction.PageJump: PageChanged(item, new RoutedPropertyChangedEventArgs <Guid>(info.ItemId, Guid.Parse(info.assetActionInfo.AssetName))); break; default: var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseClick) { return; } if (SelItemId == item.ItemId) { UnAssetAction(info, selectedItems, x, y); SelItemId = Guid.NewGuid(); } else { AssetAction(info, selectedItems, x, y); SelItemId = item.ItemId; } break; } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }; } return(item); }
public static UIElement CreateElement(SaveItemInfo info) { Canvas canvas; ToolboxItem item = null; double x, y; item = ToolboxItem.GetToolBoxItemPreview(info); item.DataContext = info; x = Canvas.GetLeft(item); y = Canvas.GetTop(item); item.MouseEnter += (sender, e) => { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (info.assetActionInfo == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseEnter) { return; } AssetAction(info, selectedItems, x, y); }; item.MouseDoubleClick += (sender, e) => { }; item.MouseLeave += (sender, e) => { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (info.assetActionInfo == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseEnter) { return; } UnAssetAction(info, selectedItems, x, y); }; item.MouseLeftButtonUp += (sender, e) => { item = sender as ToolboxItem; if (item == null) { return; } canvas = item.Parent as Canvas; if (canvas == null) { return; } if (info.assetActionInfo == null) { return; } if (string.IsNullOrEmpty(info.assetActionInfo.AssetName)) { return; } var selectedItems = canvas.Children.OfType <ToolboxItem>().FirstOrDefault(model => model.ItemName == info.assetActionInfo.AssetName); if (selectedItems == null) { return; } if (info.assetActionInfo.AssetEvent != enumAssetEvent.MouseClick) { return; } if (SelItemId == item.ItemId) { UnAssetAction(info, selectedItems, x, y); SelItemId = Guid.NewGuid(); } else { AssetAction(info, selectedItems, x, y); SelItemId = item.ItemId; } }; return(item); }