private Rect GetCalculatedSize(ElementTreeItemViewModel viewModel, double y) { Rect rect = new Rect(); if (viewModel != null) { int leafElementCount = viewModel.LeafElementCount; double pitch = _theme.MatrixCellSize + 2.0; if (viewModel.IsExpanded) { double x = viewModel.Depth * 26.0; double width = pitch; if (width > ActualWidth) { width = ActualWidth; } double height = leafElementCount * pitch; rect = new Rect(x, y, width, height); } else { double x = viewModel.Depth * 26.0; double width = ActualWidth - x + 1.0; if (width < 0) { width = 0; } double height = pitch; rect = new Rect(x, y, width, height); } } return(rect); }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { _viewModel = e.NewValue as ElementTreeItemViewModel; if (_viewModel != null) { ToolTip = _viewModel.Description; } }
private void OnMouseMove(object sender, MouseEventArgs e) { ElementTreeItemViewModel elementViewModel = GetElementViewModel(e.Source); if (elementViewModel != null) { _matrixViewModel?.HoverTreeItem(elementViewModel); } }
private void CreateChildViews(ElementTreeItemViewModel elementViewModel, double y) { foreach (ElementTreeItemViewModel child in elementViewModel.Children) { Rect rect = GetCalculatedSize(child, y); MatrixRowHeaderItemView elementView = new MatrixRowHeaderItemView(_matrixViewModel, _theme) { Height = rect.Height, Width = rect.Width }; SetTop(elementView, rect.Top); SetLeft(elementView, rect.Left); elementView.DataContext = child; Children.Add(elementView); CreateChildViews(child, y); y += rect.Height; } }
private void OnMouseDown(object sender, MouseButtonEventArgs e) { MatrixRowHeaderItemView headerItemView = e.Source as MatrixRowHeaderItemView; if (headerItemView != null) { Point pt = e.GetPosition(headerItemView); if ((pt.X < 20) && (pt.Y < 24)) { _matrixViewModel.ToggleElementExpandedCommand.Execute(null); InvalidateVisual(); } } ElementTreeItemViewModel elementViewModel = GetElementViewModel(e.Source); if (elementViewModel != null) { _matrixViewModel?.SelectTreeItem(elementViewModel); } }