public void ExportCard(string fileName) { if (fileName != null && fileName.Length > 0) { //imply selection ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardModelView card; if (selectedItem.IsLeaf) { card = selectedItem as CardModelView; } else { MessageBox.Show("There was an error saving the card. " + fileName); return; } //serialize that card IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, card); stream.Close(); //stream.Dispose(); } else { MessageBox.Show("There was an error saving the card. " + fileName); } } }
public void SetUp() { _parent = A.Fake <TreeViewItemViewModel>(); _controlService = A.Fake <ISeasonStandingsControlService>(); _division = new Division(); _sharedService = A.Fake <ISharedService>(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeview_DragOver(object sender, DragEventArgs e) { if (!Dragging) { return; } try { Point currentMousePos = e.GetPosition(this.treeviewCardSets); if (Math.Abs(currentMousePos.X - StartDragPos.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(currentMousePos.Y - StartDragPos.Y) > SystemParameters.MinimumVerticalDragDistance) { //verify that this is a valid drop target and then store the drop target TreeViewItem item = GetNearestContainer(e.OriginalSource as UIElement); ITreeViewItemViewModel itemModel = item.DataContext as ITreeViewItemViewModel; if (item != null && itemModel != null && !itemModel.IsLeaf) { e.Effects = DragDropEffects.Move; } else { e.Effects = DragDropEffects.None; } } } catch (Exception) { } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeview_Drop(object sender, DragEventArgs e) { if (!Dragging) { return; } try { e.Effects = DragDropEffects.None; e.Handled = true; //verify this is a valid drop then store the drop target TreeViewItem item = GetNearestContainer(e.OriginalSource as UIElement); ITreeViewItemViewModel itemModel = item.DataContext as ITreeViewItemViewModel; if (item != null && itemModel != null) { DropTarget = itemModel; e.Effects = DragDropEffects.Move; } } catch (Exception) { } }
public void ExportSet(string fileName) { if (fileName != null && fileName.Length > 0) { //imply selection ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardSetModelView cardSet; if (!selectedItem.IsLeaf) { cardSet = selectedItem as CardSetModelView; } else { cardSet = selectedItem.Parent as CardSetModelView; } //serialize that card IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, cardSet); stream.Close(); //XmlSerializer serializer = new XmlSerializer(cardSet.GetType()); //TextWriter writer = new StreamWriter(fileName, false, Encoding.UTF8); //serializer.Serialize(writer, cardSet); //writer.Close(); } else { MessageBox.Show("There was an error saving the card set. " + fileName); } } }
/// <summary> /// Initializes a new instance of the DivisionViewModel class. /// </summary> /// <param name="parent"></param> /// <param name="controlService"></param> /// <param name="division"></param> /// <param name="sharedService"></param> /// <param name="lazyLoadChildren"></param> public DivisionNodeViewModel(ITreeViewItemViewModel parent, ISeasonStandingsControlService controlService, Division division, ISharedService sharedService = null, bool lazyLoadChildren = false) : base(parent, controlService, sharedService, lazyLoadChildren) { // Assign argument values to member fields. _division = division ?? throw new ArgumentNullException("division"); }
public void SetUp() { _parent = A.Fake <ITreeViewItemViewModel>(); _controlService = A.Fake <ISeasonStandingsControlService>(); _conference = new Conference(); _sharedService = A.Fake <ISharedService>(); }
/// <summary> /// Initializes a new instance of the Conference class. /// </summary> /// <param name="parent"></param> /// <param name="controlService"></param> /// <param name="conference"></param> /// <param name="sharedService"></param> /// <param name="lazyLoadChildren"></param> public ConferenceNodeViewModel(ITreeViewItemViewModel parent, ISeasonStandingsControlService controlService, Conference conference, ISharedService sharedService = null, bool lazyLoadChildren = true) : base(parent, controlService, sharedService, lazyLoadChildren) { // Assign argument values to member fields. _conference = conference ?? throw new ArgumentNullException("conference"); }
/// <summary> /// Initializes a new instance of the <see cref="SubTopicViewModel"/> class. /// </summary> /// <param name="subtopic">The subtopic.</param> /// <param name="parent">The parent.</param> public SubTopicViewModel(Topic subtopic, ITreeViewItemViewModel parent) : base(parent) { IsSubTopic = true; Entity = subtopic; _oldSubtopicName = Entity.Name; }
/// <summary> /// /// </summary> /// <param name="selectedItem"></param> public void RemoveSet(ITreeViewItemViewModel selectedItem) { if (selectedItem == null) { //imply selection selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardSetModelView setModel; if (!selectedItem.IsLeaf) { setModel = selectedItem as CardSetModelView; } else { return; } CardSets.Remove(setModel); NotifyPropertyChanged("CardSets"); NotifyPropertyChanged("ObservableCardSets"); } } else { CardSetModelView set = selectedItem as CardSetModelView; if (set != null && CardSets.Contains(set)) { CardSets.Remove(set); NotifyPropertyChanged("CardSets"); NotifyPropertyChanged("ObservableCardSets"); } } }
/// <summary> /// /// </summary> /// <param name="selectedSet"></param> public void AddCard(ITreeViewItemViewModel selectedSetRoot) { if (selectedSetRoot == null) { //imply selection ITreeViewItemViewModel selectedSet = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedSet != null) { CardSetModelView setModel; if (selectedSet.IsLeaf) { setModel = selectedSet.Parent as CardSetModelView; } else { setModel = selectedSet as CardSetModelView; } setModel.Cards.Add(new CardModelView(setModel)); NotifyPropertyChanged("CardSets"); NotifyPropertyChanged("ObservableCardSets"); setModel.IsExpanded = true; } } }
public FileViewModel(ViewModelBase root, FromSoftwareFile fromSoftwareFile, ITreeViewItemViewModel parent) : base(root, parent, fromSoftwareFile.IsDirectory) { FromSoftwareFile = fromSoftwareFile; CanBeEdited = true; _backupFileName = fromSoftwareFile.FileName; FileName = fromSoftwareFile.FileName; }
/// <summary> /// Initializes a new instance of the <see cref="TreeViewItemViewModel"/> class. /// </summary> /// <param name="parent">The parent.</param> protected TreeViewItemViewModel(ITreeViewItemViewModel parent) { InitCommands(); Parent = parent; ChildrenCollectionView = new ObservableCollection <ITreeViewItemViewModel>(); Visibility = Visibility.Visible; }
public static void InitializeChildren(ITreeViewItemViewModel vm, bool loadChildren) { if (loadChildren) { vm.Children = new ObservableCollection <ITreeViewItemViewModel> { null }; } }
protected TreeViewItemViewModel(ViewModelBase root, ITreeViewItemViewModel parent, bool lazyLoadChildren) { Root = root; Parent = parent; Children = new ObservableCollection <ITreeViewItemViewModel>(); if (lazyLoadChildren) { Children.Add(DummyChild); } }
public static void ExpandCheck(ITreeViewItemViewModel vm, ITreeViewItemViewModel parent, Func <Task> LoadChildrenAsync) { if (vm.IsExpanded && parent != null) { parent.IsExpanded = true; } if (vm.HasDummyChild) { vm.Children.Clear(); Task.Run(async() => await LoadChildrenAsync()); } }
internal static void CheckForEndTag(ITreeViewItemViewModel vm, ReferenceDescription node) { //if (displayName.Text.Contains(":")) //{ // Datatype = displayName.Text.Substring(displayName.Text.IndexOf(":") + 1); // Name = displayName.Text.Substring(0, displayName.Text.IndexOf(":")); // vm.Children.Clear(); //} //else //{ // Datatype = string.Empty; // Name = displayName; //} }
/// <summary> /// Comprueba si un nodo estaba en la lista de nodos abiertos /// </summary> private bool Checkexpanded(ITreeViewItemViewModel node, List <Tuple <string, string> > nodesExpanded) { // Recorre la colección foreach (Tuple <string, string> nodeExpanded in nodesExpanded) { if (nodeExpanded.Item1.EqualsIgnoreCase(node.GetType().ToString()) && nodeExpanded.Item2.EqualsIgnoreCase(node.NodeID)) { return(true); } } // Si ha llegado hasta aquí es porque no ha encontrado nada return(false); }
private void treeview_MouseMove(object sender, MouseEventArgs e) { if (!Dragging) { return; } try { if (e.LeftButton == MouseButtonState.Pressed) { Point currentMousePos = e.GetPosition(this.treeviewCardSets); if (Math.Abs(currentMousePos.X - StartDragPos.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(currentMousePos.Y - StartDragPos.Y) > SystemParameters.MinimumVerticalDragDistance) { DraggedItem = this.treeviewCardSets.SelectedItem as ITreeViewItemViewModel; if (DraggedItem != null) { DragDropEffects finalDropEffect = DragDrop.DoDragDrop(this.treeviewCardSets, this.treeviewCardSets.SelectedValue, DragDropEffects.Move); //ensure target is not null and item is dragging if (finalDropEffect == DragDropEffects.Move && DropTarget != null) { if (DropTarget.IsLeaf) { CardSetModelView set = DropTarget.Parent as CardSetModelView; set.TransferCard(DraggedItem as CardModelView); DropTarget = null; DraggedItem = null; } else { //copy card to target set //then remove references CardSetModelView set = DropTarget as CardSetModelView; set.TransferCard(DraggedItem as CardModelView); DropTarget = null; DraggedItem = null; } } } } } } catch (Exception) { } return; }
protected TreeViewItemViewModelBase(string name, string content, ITreeViewItemViewModel parent, bool isExpandable) { Name = name; Content = content; Parent = parent; if (!isExpandable) { return; } Children = new ObservableCollection <ITreeViewItemViewModel> { LoadingDummyTreeViewItemViewModel.Instance }; }
public TreeViewItemViewModel(string nodeID, string text, ITreeViewItemViewModel parent = null, bool lazyLoadChildren = true, object tag = null) { NodeID = nodeID; Text = text; LazyLoadChildren = lazyLoadChildren; Parent = parent; Tag = tag; ForegroundBrush = System.Windows.Media.Brushes.Black; BackgroundBrush = null; if (lazyLoadChildren) { Children.Add(new TreeViewItemViewModel(null, "-----", this, false)); } }
private void treeview_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { TreeViewItem item = sender as TreeViewItem; ITreeViewItemViewModel itemModel = item.DataContext as ITreeViewItemViewModel; if (item != null && itemModel != null && itemModel.IsLeaf) { StartDragPos = e.GetPosition(this.treeviewCardSets); Dragging = true; ActiveCard = itemModel as CardModelView; item.Focus(); } } }
/// <inheritdoc /> protected override void OnHeaderChanged(object oldHeader, object newHeader) { base.OnHeaderChanged(oldHeader, newHeader); var old = oldHeader as ITreeViewItemViewModel; if (old != null) { old.PropertyChanged -= HeaderOnPropertyChanged; } _model = newHeader as ITreeViewItemViewModel; if (_model != null) { _model.PropertyChanged += HeaderOnPropertyChanged; IsExpanded = _model.IsExpanded; IsSelected = _model.IsSelected; } }
public void ImportCard(string fileName) { if (fileName != null && fileName.Length > 0) { //imply selection ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardSetModelView cardSet; if (selectedItem.IsLeaf) { cardSet = selectedItem.Parent as CardSetModelView; } else { cardSet = selectedItem as CardSetModelView; } //serialize that card IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); CardModelView card = (CardModelView)formatter.Deserialize(stream); stream.Close(); if (card == null) { MessageBox.Show("The card did not load properly. " + fileName); return; } cardSet.AddCardToSet(card); NotifyPropertyChanged("CardSets"); NotifyPropertyChanged("ObservableCardSets"); cardSet.IsExpanded = true; ActiveCard = card; } else { MessageBox.Show("There was an error loading the card. " + fileName); } } }
/// <summary> /// Initializes a new instance of the TreeViewItemViewModel class. /// </summary> /// <param name="parent"></param> /// <param name="controlService"></param> /// <param name="sharedService"></param> /// <param name="lazyLoadChildren"></param> protected TreeViewItemViewModel(ITreeViewItemViewModel parent, ISeasonStandingsControlService controlService, ISharedService sharedService = null, bool lazyLoadChildren = true) : base(sharedService) { Parent = parent; _controlService = controlService; try { Children = new ObservableCollection <ITreeViewItemViewModel>(); if (lazyLoadChildren) { Children.Add(DummyChild); } } catch (Exception ex) { _sharedService.ShowExceptionMessage(ex); } }
/// <summary> /// /// </summary> /// <param name="selectedItem"></param> public void RemoveCard(ITreeViewItemViewModel selectedItem) { if (selectedItem == null) { //imply selection selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardSetModelView setModel; if (selectedItem.IsLeaf) { setModel = selectedItem.Parent as CardSetModelView; } else { return; } setModel.Cards.Remove(selectedItem); NotifyPropertyChanged("CardSets"); NotifyPropertyChanged("ObservableCardSets"); } } }
public void RenameSet() { //imply selection ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel; if (selectedItem != null) { CardSetModelView setModel; if (!selectedItem.IsLeaf) { setModel = selectedItem as CardSetModelView; } else { return; } TreeViewItem item = this.treeviewCardSets.ItemContainerGenerator.ContainerFromItem(this.treeviewCardSets.SelectedItem) as TreeViewItem; //myTree.ItemContainerGenerator.ContainerFromItem(SelectedItem) as TreeViewItem if (item == null) { MessageBox.Show("Oh no"); return; } GeneralTransform myTransform = item.TransformToAncestor(treeviewCardSets); Point myOffset = myTransform.Transform(new Point(0, 0)); // myOffset.Y contains your distance from the top of the treeview now textboxRenamer.Margin = new Thickness(10.0, myOffset.Y + 32.0, 0, 0); SelectedSet = setModel; this.textboxRenamer.Visibility = System.Windows.Visibility.Visible; this.textboxRenamer.IsEnabled = true; this.textboxRenamer.Text = setModel.Name; this.textboxRenamer.Focus(); } }
public OpcComputer(string name, ITreeViewItemViewModel _parent, bool loadChildren = false) { ComputerName = name; parent = _parent; TreeViewItemViewModelHelpers.InitializeChildren(this, loadChildren); }
public TfsTeamProject(TeamProject teamProject, ITreeViewItemViewModel parent) : base(teamProject.Name, parent, true) { m_teamProject = teamProject; ImageNormal = @"..\Icons\16\SourcesA.png"; ImageMaster = @"..\Icons\16\SourcesCA.png"; }
/// <summary> /// Initializes a new instance of the <see cref="SubTopicViewModel"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="parent">The parent.</param> public SubTopicViewModel(string name, ITreeViewItemViewModel parent) : base(null) { Entity = new Topic(parent.TopicCategory, name); _oldSubtopicName = Entity.Name; }
public void Setup() { _model = new TreeViewItemViewModel(); }
protected TreeViewItemViewModel(string name, ITreeViewItemViewModel parent, bool lazyLoadChildren) : base(name) { Parent = parent; m_items = new List<ITreeViewItemViewModel>(); if (lazyLoadChildren) m_items.Add(DummyChild); }