コード例 #1
0
ファイル: DiagramVM.cs プロジェクト: wwwK/wpf-demos
        /// <summary>
        /// The on view loaded.
        /// </summary>
        /// <param name="param">
        /// The param.
        /// </param>
        private async void OnViewLoaded(object param)
        {
            IGraphInfo graph = this.Info as IGraphInfo;

            graph.ItemAdded        += this.DiagramVM_ItemAdded;
            graph.ItemDropEvent    += this.Graph_ItemDropEvent;
            graph.ItemDeleted      += this.DiagramVM_ItemDeleted;
            graph.GetDrawType      += this.graph_GetDrawType;
            graph.NodeChangedEvent += this.Graph_NodeChangedEvent;
            await this.Load();

            PageVM page = this.PageSettings as PageVM;

            if (this._isValidXml)
            {
                graph.Commands.Zoom.Execute(new ZoomPositionParameter {
                    ZoomTo = page.Scale
                });
                this.ScrollSettings.ScrollInfo.PanTo(new Point(page.HOffset, page.VOffset));
            }

            this.IsBusy = Visibility.Collapsed;

            if (this is OrganizationChartDiagramVM)
            {
                OrganizationChartNodeVM node = (this.Nodes as ObservableCollection <OrganizationChartNodeVM>).First() as OrganizationChartNodeVM;
                node.OffsetX = 550;
                node.OffsetY = 125;
                this.LayoutManager.Layout.UpdateLayout(node);
            }
        }
コード例 #2
0
        async private void Onuploadcommand(object obj)
        {
            var picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }
            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            BitmapImage image = new BitmapImage();

            image.SetSource(stream);
            IGraphInfo graph = this.Info as IGraphInfo;
            NodeVM     node  = new NodeVM();

            node.OffsetX    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2;
            node.OffsetY    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2;
            node.UnitHeight = 100;
            node.UnitWidth  = 100;
            node.Content    = new Image()
            {
                Source = image, Stretch = Stretch.Fill
            };
            (Nodes as ObservableCollection <NodeVM>).Add(node);
        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();

            //Initialize Nodes and Connectors
            var nodes = new ObservableCollection <CustomNode>();

            Diagram.Connectors = new ObservableCollection <ConnectorViewModel>();
            Diagram.Nodes      = nodes;

            //Collection Changed event to update the Node
            nodes.CollectionChanged += (s, e) =>
            {
                if (e.NewItems != null)
                {
                    (e.NewItems[0] as CustomNode).Update();
                }
            };

            //Create Nodes
            CreateNodes();

            //Initialize PageSettings,Snapping,Ruler and Constraints
            InitializeDiagram();
            IGraphInfo info = Diagram.Info as IGraphInfo;

            info.ItemAdded += Info_ItemAdded;
        }
コード例 #4
0
        private async void OnViewLoaded(object param)
        {
            if (!_isCustomVM)
            {
                IGraphInfo graph = Info as IGraphInfo;
                graph.ItemAdded   += DiagramVM_ItemAdded;
                graph.ItemDeleted += DiagramVM_ItemDeleted;
                await Load();

                PageVM page = PageSettings as PageVM;
                if (_isValidXml)
                {
                    graph.Commands.Zoom.Execute(
                        new ZoomPositionParamenter()
                    {
                        ZoomTo = page.Scale
                    });
                    (this.Info as IGraph).ScrollSettings.ScrollInfo.PanTo(new Point(page.HOffset, page.VOffset));
                }
                else
                {
                    await Save();

                    (Info as IGraphInfo).Commands.FitToPage.Execute(
                        new FitToPageParameter
                    {
                        FitToPage = FitToPage.FitToPage,
                        Margin    = new Thickness(20)
                    }
                        );
                    await this.Save();
                }
                IsBusy = Visibility.Collapsed;
            }
        }
コード例 #5
0
ファイル: Diagram.cs プロジェクト: phanithken/UWP
 void Diagram_Loaded(object sender, RoutedEventArgs e)
 {
     if (this.DataContext is DiagramVM)
     {
         (this.DataContext as DiagramVM).ScrollSettings = this.ScrollSettings;
     }
     if (this.DataContext != null && (this.DataContext as DiagramVM)._isValidXml)
     {
         IGraphInfo graph = (sender as SfDiagram).Info as IGraphInfo;
         (sender as SfDiagram).Constraints = (sender as SfDiagram).Constraints | GraphConstraints.Undoable;
         PageVM page = (this.DataContext as DiagramVM).PageSettings as PageVM;
         graph.Commands.Zoom.Execute(
             new ZoomPositionParamenter()
         {
             ZoomTo = page.Scale
         });
         if (this.ScrollSettings.ScrollInfo != null)
         {
             this.ScrollSettings.ScrollInfo.PanTo(new Point(page.HOffset, page.VOffset));
         }
         (this.DataContext as DiagramVM).HorizontalRuler = this.HorizontalRuler;
         (this.DataContext as DiagramVM).VerticalRuler   = this.VerticalRuler;
     }
     this.CommandManager.View = (Control)Window.Current.Content;
 }
コード例 #6
0
        public async void OnSaveAsCommand(object param)
        {
            var savePicker = new FileSavePicker();

            savePicker.DefaultFileExtension = ".mock";
            savePicker.FileTypeChoices.Add(".mock", new List <string> {
                ".mock"
            });
            savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            savePicker.SuggestedFileName      = "Export.mock";

            // Prompt the user to select a file
            var saveFile = await savePicker.PickSaveFileAsync();

            // Verify the user selected a file
            if (saveFile == null)
            {
                return;
            }

            IGraphInfo graph = this.SelectedDiagram.Info as IGraphInfo;
            PageVM     page  = this.SelectedDiagram.PageSettings as PageVM;

            page.Scale = SelectedDiagram.ScrollSettings.ScrollInfo.CurrentZoom;
            // Encode the image to the selected file on disk
            using (Stream fileStream = await saveFile.OpenStreamForWriteAsync())
            {
                graph.Save(fileStream);
            }
        }
コード例 #7
0
        async public void OnCapturesCommand(object param)
        {
            MediaCapture takePhotoManager = new MediaCapture();
            await takePhotoManager.InitializeAsync();

            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            IStorageFile            file      = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                "Photo.jpg", CreationCollisionOption.GenerateUniqueName);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);

            //Windows.Storage.StorageFile file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(fileStream);

                IGraphInfo graph = this.Info as IGraphInfo;
                NodeVM     node  = new NodeVM();
                node.OffsetX    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2;
                node.OffsetY    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2;
                node.UnitHeight = 100;
                node.UnitWidth  = 100;
                node.Content    = new Image()
                {
                    Source = bitmap, Stretch = Stretch.Fill
                };
                (Nodes as ObservableCollection <NodeVM>).Add(node);
            }
        }
コード例 #8
0
        public MainWindow()
        {
            InitializeComponent();
            IGraphInfo info = diagram.Info as IGraphInfo;

            info.ItemAdded += info_ItemAdded;
        }
コード例 #9
0
        public async Task Save()
        {
            //try
            //{
            IGraphInfo graph = this.Info as IGraphInfo;
            PageVM     page  = PageSettings as PageVM;

            if (graph != null && graph.ScrollInfo != null)
            {
                page.HOffset = graph.ScrollInfo.HorizontalOffset;
                page.VOffset = graph.ScrollInfo.VerticalOffset;
                page.Scale   = graph.ScrollInfo.CurrentZoom;


                string        pathString = System.IO.Path.Combine(installedLocation, "DiagramBuilder");
                DirectoryInfo DI         = new DirectoryInfo(_file);
                string        file       = DI.Name;
                if (File.Exists(pathString + "/" + file.ToString()))
                {
                    File.Delete(pathString + "/" + file.ToString());
                }

                File.Create(pathString + "/" + file.ToString()).Close();
                _file = pathString + "/" + file.ToString();
                using (FileStream fileStream = File.OpenWrite(_file))
                {
                    graph.Save(fileStream);
                }
                _isValidXml = true;
            }
            //  }
            //catch
            //{ }
        }
コード例 #10
0
        private void Group_Click(object sender, RoutedEventArgs e)
        {
            IGraphInfo graphinfo = diagram.Info as IGraphInfo;

            //UnGroups the selected group elements.
            graphinfo.Commands.Group.Execute(null);
        }
コード例 #11
0
        async private void SinglePageExporting(string p, Guid guid)
        {
            IGraphInfo graph = this.Info as IGraphInfo;

            if (graph != null)
            {
                var savePicker = new FileSavePicker();
                savePicker.DefaultFileExtension = "." + p;
                savePicker.FileTypeChoices.Add("." + p, new List <string> {
                    "." + p
                });
                savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                savePicker.SuggestedFileName      = Title;

                // Prompt the user to select a file
                var saveFile = await savePicker.PickSaveFileAsync();

                // Verify the user selected a file
                if (saveFile == null)
                {
                    return;
                }
                // Encode the image to the selected file on disk
                using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    ExportSettings.ExportBitmapEncoder = await BitmapEncoder.CreateAsync(guid, fileStream);

                    ExportSettings.ExportStream = fileStream;
                    //Method to Export the SfDiagram
                    await graph.Export();
                }
            }
        }
コード例 #12
0
ファイル: DiagramVM.cs プロジェクト: wwwK/wpf-demos
        /// <summary>
        /// Represents the save method execution
        /// </summary>
        /// <param name="savedPath">
        /// The savedPath.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task Save(string savedPath)
        {
            // try
            // {
            IGraphInfo graph = this.Info as IGraphInfo;
            PageVM     page  = this.PageSettings as PageVM;

            if (graph != null && this.ScrollSettings.ScrollInfo != null)
            {
                page.HOffset = this.ScrollSettings.ScrollInfo.HorizontalOffset;
                page.VOffset = this.ScrollSettings.ScrollInfo.VerticalOffset;
                page.Scale   = this.ScrollSettings.ScrollInfo.CurrentZoom;

                this._file = savedPath;
                using (FileStream fileStream = File.OpenWrite(this._file))
                {
                    graph.Save(fileStream);
                }

                this._isValidXml = true;
            }

            // }
            // catch
            // { }
        }
コード例 #13
0
        // This resets the zoom level to 1
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IGraphInfo graphinfo = SFD.Info as IGraphInfo;

            graphinfo.Commands.Reset.Execute(new ResetParameter()
            {
                Reset = Reset.Zoom
            });
        }
コード例 #14
0
        private void Addsubmenu()
        {
            IGraphInfo diagramInfo = (Diagram.Info as IGraphInfo);

            DiagramMenuItem menu = new DiagramMenuItem()
            {
                Content = "Delete",
                Command = diagramInfo.Commands.Delete,
                Icon    = @"pack://*****:*****@"pack://application:,,,/Icons/zoom.jpg",
            };

            //Intialize the sub-menu item for Zooming menu with ZoomIn command
            DiagramMenuItem zoomIn = new DiagramMenuItem()
            {
                // Defines the content of menu item
                Content = "ZoomIn",
                // Defines the icon that appears in menu item - it accepts the image path.
                Icon = @"pack://*****:*****@"pack://application:,,,/Icons/zoomout.png",
                Command          = diagramInfo.Commands.Zoom,
                CommandParameter = new ZoomPositionParameter()
                {
                    ZoomFactor = 0.5, ZoomCommand = ZoomCommand.ZoomOut
                }
            };


            Zoom.Items = new ObservableCollection <DiagramMenuItem>();
            //Adding zooming menus into diagram menu as to add sub-menu items.
            Zoom.Items.Add(zoomIn);
            Zoom.Items.Add(zoomOut);

            //Adding zooming menu into diagram default menu.
            Diagram.Menu.MenuItems.Add(Zoom);
        }
コード例 #15
0
        // This zooms the view out
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            IGraphInfo graphinfo = SFD.Info as IGraphInfo;

            graphinfo.Commands.Zoom.Execute(new ZoomPositionParamenter()
            {
                ZoomFactor  = 0.5,
                ZoomCommand = ZoomCommand.ZoomOut
            });
        }
コード例 #16
0
        void OrgDiagram_Unloaded(object sender, RoutedEventArgs e)
        {
            sfdiagram.LayoutManager = null;
            //sfdiagram.ViewDictionary = null;
            this.Unloaded -= OrgDiagram_Unloaded;
            IGraphInfo graphInfo = sfdiagram.Info as IGraphInfo;

            ;
            foreach (IConnector connector in (IEnumerable <object>)sfdiagram.Connectors)
            {
                connector.SourceNode = null;
                connector.TargetNode = null;
            }

            foreach (FrameworkElement child in sfdiagram.Page.Children)
            {
                if (child is Node)
                {
                    OrgNodeViewModel vm = child.DataContext as OrgNodeViewModel;
                    if (vm != null)
                    {
                        vm.CustomToolTip = null;
                    }
                    child.MouseEnter          -= Node_PointerEntered_1;
                    child.MouseLeave          -= Node_PointerExited_1;
                    child.MouseLeftButtonDown -= Node_PointerPressed_1;
                }
                child.DataContext = null;
            }

            sfdiagram.Nodes      = null;
            sfdiagram.Connectors = null;

            SelectorViewModel selec = sfdiagram.SelectedItems as SelectorViewModel;

            if (selec != null)
            {
                selec.Connectors = null;
                selec.Nodes      = null;
                selec.Groups     = null;
            }
            sfdiagram.DataContext   = null;
            sfdiagram.SFSelector    = null;
            sfdiagram.SelectedItems = null;
            this.DataContext        = null;
            DiagramCommand.SetCommand(sfdiagram, null);

            this.Loaded   -= OrgDiagram_Loaded;
            this.Unloaded -= OrgDiagram_Unloaded;
            if (sfdiagram != null)
            {
                sfdiagram.Loaded    -= sfdiagram_Loaded;
                sfdiagram.MouseMove -= sfdiagram_PointerMoved;
            }
        }
コード例 #17
0
        /// <summary>
        /// Method will execute when Import executed
        /// </summary>
        private void ImportExecute(object param)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Do you want to save Diagram?", "Diagram Builder", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                this.Save.Execute(null);
            }

            OpenFileDialog openDialogBox = new OpenFileDialog();

            openDialogBox.Title = "File Open";
            if (openDialogBox.ShowDialog() == true)
            {
                (SelectedDiagram as BrainstormingVM).addChildAtLeft = false;
                IGraphInfo graph = this.Info as IGraphInfo;

                using (Stream stream = openDialogBox.OpenFile())
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(stream);
                    foreach (XmlNode brainstrom in xml.ChildNodes)
                    {
                        if (brainstrom.LocalName.Equals("Brainstorm"))
                        {
                            (SelectedDiagram.Nodes as ObservableCollection <BrainstormingNodeVM>).Clear();
                            (SelectedDiagram.Connectors as ObservableCollection <BrainstormingConnectorVM>).Clear();
                            foreach (XmlNode rootTopic in brainstrom.ChildNodes)
                            {
                                (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Rootnode = (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).AddRootNode();
                                (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Updatebowtielayout("root");
                                foreach (XmlNode att in rootTopic.ChildNodes)
                                {
                                    if (att.LocalName.Equals("text"))
                                    {
                                        //((SelectedDiagram.Rootnode.Annotations as AnnotationCollection)[0] as TextAnnotationViewModel).Text = att.InnerText;
                                        (((SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Rootnode.Annotations as List <IAnnotation>)[0] as LabelVM).Content = att.InnerText;
                                    }
                                    if (att.LocalName.Equals("topic"))
                                    {
                                        ((SelectedDiagram.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Clear();
                                        (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Rootnode.IsSelected = true;
                                        //(SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).addChildAtLeft = false;// (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).addChildAtLeft ? false : true;
                                        DeSeriaizeChild((SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Rootnode, att);
                                    }
                                }
                            }
                        }
                    }
                }
                (SelectedDiagram as BrainstormingVM).Updatebowtielayout("root");
            }
        }
コード例 #18
0
        void diagramControl_Unloaded(object sender, RoutedEventArgs e)
        {
            diagramControl.PointerReleased -= diagramControl_PointerReleased;
            diagramControl.KnownTypes       = null;
            this.Unloaded -= diagramControl_Unloaded;
            //Info - for Diagram Events and Commands
            IGraphInfo info = diagramControl.Info as IGraphInfo;

            //Event to notify the when Items added
            info.ItemAdded -= info_ItemAdded;
            //Register CollectionChanged Event
            (this.diagramControl.Nodes as NodeVmCollection).CollectionChanged -= Nodes_CollectionChanged;
        }
コード例 #19
0
 private async Task Load()
 {
     if (_file != null && _isValidXml)
     {
         IGraphInfo graph = this.Info as IGraphInfo;
         using (FileStream fileStream = File.OpenRead(_file))
         {
             graph.Load(fileStream);
         }
         PageSettings = new PageVM();
         (PageSettings as PageVM).InitDiagram(this);
     }
 }
コード例 #20
0
        public MainWindow()
        {
            InitializeComponent();

            //Initialize PageSettings ,Snapping and Constraints
            InitializeDiagram();
            diagramcontrol.CommandManager.View = Application.Current.MainWindow;

            //Info - for Diagram Events and Commands
            IGraphInfo info = diagramcontrol.Info as IGraphInfo;

            //Event to notify the when Items added
            info.ItemAdded += info_ItemAdded;
        }
コード例 #21
0
        private void InitializeEvents()
        {
            IGraphInfo graphInfo = sfdiagram.Info as IGraphInfo;

            //Tapped Event for Diagram (Item-Node or Connector)
            graphInfo.ItemTappedEvent += sfdiagram_ItemTappedEvent;

            //Events for SfDiagram
            sfdiagram.MouseMove += sfdiagram_PointerMoved;

            //To Clear Values
            sfdiagram.Loaded += sfdiagram_Loaded;
            this.Loaded      += OrgDiagram_Loaded;
            this.Unloaded    += OrgDiagram_Unloaded;
        }
コード例 #22
0
        public MainWindow()
        {
            InitializeComponent();

            //Register CollectionChanged event
            nodes.CollectionChanged += Nodes_CollectionChanged;

            //Initialize PageSettings and Snapping
            InitializeDiagram();

            //Info - for Diagram Events and Commands
            IGraphInfo info = diagramControl.Info as IGraphInfo;

            //Event to notify the when Items added
            info.ItemAdded += info_ItemAdded;
        }
コード例 #23
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DiagramStyleWindow" /> class.
        /// </summary>
        public DiagramStyleWindow()
        {
            this.InitializeComponent();
            this.diagramcontrol.PageSettings = new PageSettings()
            {
                PageWidth = 400, PageHeight = 400
            };
            FitToPageParameter fitToPage = new FitToPageParameter
            {
                FitToPage = FitToPage.FitToPage, Region = Region.PageSettings
            };
            IGraphInfo graphInfo = this.diagramcontrol.Info as IGraphInfo;

            if (graphInfo != null)
            {
                graphInfo.Commands.FitToPage.Execute(fitToPage);
            }
        }
コード例 #24
0
        public async void OnDuplicateCommand(object param)
        {
            StorageFile s          = null;
            DiagramVM   newDiagram = null;
            //Task task = null;
            string parameter = Guid.NewGuid().ToString("N");

            //if (EnsureUnsnapped())
            {
                s = await installedLocation.CreateFileAsync(parameter + ".mock", CreationCollisionOption.FailIfExists);
            }
            if (s != null)
            {
                IGraphInfo graph = SelectedDiagram.Info as IGraphInfo;
                PageVM     page  = SelectedDiagram.PageSettings as PageVM;
                if (graph != null && SelectedDiagram.ScrollSettings.ScrollInfo != null)
                {
                    page.HOffset = SelectedDiagram.ScrollSettings.ScrollInfo.HorizontalOffset;
                    page.VOffset = SelectedDiagram.ScrollSettings.ScrollInfo.VerticalOffset;
                    page.Scale   = SelectedDiagram.ScrollSettings.ScrollInfo.CurrentZoom;
                    using (Stream stream = await s.OpenStreamForWriteAsync())
                    {
                        graph.Save(stream);
                    }
                    newDiagram = new DiagramVM(s, true);

                    Diagrams.Add(newDiagram);
                    SelectedDiagram             = newDiagram;
                    newDiagram.EditTile         = true;
                    newDiagram.PropertyChanged += (diagram, e) =>
                    {
                        DiagramVM sender = diagram as DiagramVM;
                        if (e.PropertyName == "IsSelected")
                        {
                            if (sender.IsSelected == true)
                            {
                                this.SelectedDiagram = sender;
                            }
                        }
                    };
                    await SaveFileIndex();
                }
            }
        }
コード例 #25
0
ファイル: DiagramVM.cs プロジェクト: wwwK/wpf-demos
        /// <summary>
        /// The on flip command.
        /// </summary>
        /// <param name="obj">
        /// The obj.
        /// </param>
        private void OnFlipCommand(object obj)
        {
            IGraphInfo graphInfo = this.Info as IGraphInfo;

            if (obj.ToString().Equals("HorizontalFlip"))
            {
                graphInfo.Commands.Flip.Execute(
                    new FlipParameter {
                    Flip = Flip.HorizontalFlip, FlipMode = FlipMode.FlipMode
                });
            }
            else if (obj.ToString().Equals("VerticalFlip"))
            {
                graphInfo.Commands.Flip.Execute(
                    new FlipParameter {
                    Flip = Flip.VerticalFlip, FlipMode = FlipMode.FlipMode
                });
            }
        }
コード例 #26
0
 private async Task Load()
 {
     try
     {
         if (_isValidXml)
         {
             IGraphInfo graph = this.Info as IGraphInfo;
             //using (Stream stream = _file.OpenStreamForReadAsync().GetAwaiter().GetResult())
             using (Stream stream = await _file.OpenStreamForReadAsync())
             {
                 graph.Load(stream);
             }
             PageSettings = new PageVM();
             (PageSettings as PageVM).InitDiagram(this);
         }
     }
     catch
     { }
 }
コード例 #27
0
        void SelectedSymbol_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
        {
            if (this.SelectedDiagram.SelectedItems != null && ((this.SelectedDiagram.SelectedItems as SelectorVM).Nodes as ICollection <object>).Count > 0)
            {
                ((this.SelectedDiagram.SelectedItems as SelectorVM).Nodes as ICollection <object>).Clear();
            }
            NodeVM     node  = new NodeVM();
            IGraphInfo graph = this.SelectedDiagram.Info as IGraphInfo;

            node.OffsetX         = (SelectedDiagram.ScrollSettings.ScrollInfo.ViewportWidth) / 2;
            node.OffsetY         = (SelectedDiagram.ScrollSettings.ScrollInfo.ViewportHeight) / 2;
            node.UnitWidth       = 100;
            node.UnitHeight      = 100;
            node.Content         = Stencil.SelectedSymbol.Content;
            node.ContentTemplate = Stencil.SelectedSymbol.ContentTemplate;
            node.IsSelected      = true;
            this.SelectedDiagram.NodeCollection.Add(node);
            e.Handled = true;
        }
コード例 #28
0
ファイル: GraphInfo.cs プロジェクト: keepingcode/paper
        public GraphInfo(Type type)
        {
            var isDataContract = type.GetCustomAttributes(typeof(DataContractAttribute), true).Any();
            var isXml          =
                type.GetCustomAttributes(typeof(XmlTypeAttribute), true).Any() ||
                type.GetCustomAttributes(typeof(XmlRootAttribute), true).Any();

            if (isDataContract)
            {
                instancia = new DataContractGraphInfo(type);
            }
            else if (isXml)
            {
                instancia = new XmlGraphInfo(type);
            }
            else
            {
                instancia = new ObjectGraphInfo(type);
            }
        }
コード例 #29
0
        //   ObservableCollection<CustomNode> nodes = null;
        public Selector()
        {
            this.InitializeComponent();

            //Register CollectionChanged Event
            (this.diagramControl.Nodes as NodeVmCollection).CollectionChanged += Nodes_CollectionChanged;

            //Initialize PageSettings
            InitializeDiagram();

            //Unload the Diagram
            this.Unloaded += diagramControl_Unloaded;


            //Info - for Diagram Events and Commands
            IGraphInfo info = diagramControl.Info as IGraphInfo;

            //Event to notify the when Items added
            info.ItemAdded += info_ItemAdded;
        }
コード例 #30
0
        public async void OnImportCommand(object param)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            fileOpenPicker.FileTypeFilter.Clear();
            fileOpenPicker.FileTypeFilter.Add(".mock");
            StorageFile file = await fileOpenPicker.PickSingleFileAsync();

            (this.SelectedDiagram.Nodes as ObservableCollection <NodeVM>).Clear();
            (this.SelectedDiagram.Connectors as ObservableCollection <ConnectorVM>).Clear();
            (this.SelectedDiagram.Groups as ObservableCollection <GroupVM>).Clear();
            IGraphInfo graph = this.SelectedDiagram.Info as IGraphInfo;

            using (Stream stream = await file.OpenStreamForReadAsync())
            {
                graph.Load(stream);
            }
            (this.SelectedDiagram.PageSettings as PageVM).InitDiagram();
            (this.SelectedDiagram.PageSettings as PageVM).InitDiagram(this.SelectedDiagram);
        }