示例#1
0
        public PopupWindow(Visual parentControl, TreeNodeViewModel viewModel)
        {
            if (parentControl != null)
            {
                // Get absolute location on screen of upper left corner of the TextBlock
                Point locationFromScreen = parentControl.PointToScreen(new Point(0, 0));
                locationFromScreen.Y += 18;                                               // SystemParameters.WindowCaptionHeight;
                locationFromScreen.X -= 6;                                                // correction
                                                                                          // Transform screen point to WPF device independent point
                PresentationSource source = PresentationSource.FromVisual(parentControl); // this
                Point targetPoints        = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen);
                Top  = targetPoints.Y;
                Left = targetPoints.X;

                AllowsTransparency    = false;
                WindowStyle           = WindowStyle.None;
                ResizeMode            = ResizeMode.CanResize;
                WindowStartupLocation = WindowStartupLocation.Manual;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            SizeToContent = SizeToContent.Manual;
            Width         = 200;
            Height        = 300;

            viewModel.SelectedItemChanged = new RelayCommand(SelectedItemChangedHandler);
            Content = new TreeNodeView()
            {
                DataContext = viewModel
            };
        }
示例#2
0
        private void SelectedItemChangedHandler(object parameter)
        {
            var args = parameter as RoutedPropertyChangedEventArgs <object>;

            if (args == null)
            {
                return;
            }
            args.Handled = true;
            Result       = args.NewValue as TreeNodeViewModel;
            this.Close();
        }