Exemplo n.º 1
0
        private void SkillInfo_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
            {
                var control    = sender as PlayerInfoControl;
                var playerInfo = control?.PlayerInfo;
                if (playerInfo != null)
                {
                    var vm = new SkillBreakdownViewModel(playerInfo);
                    var v  = new SkillBreakdownView(vm)
                    {
                        Owner = this
                    };
                    var headerHeight = 27;//approximate height of the title bar on the skill breakdown window
                    var ownedWindows = OwnedWindows.Cast <Window>().Where(w => w.IsVisible).ToList();
                    if (!ownedWindows.Any())
                    {
                        //we should move away from windows form here if possible.
                        Screen screen = Screen.FromHandle(new WindowInteropHelper(this).Handle);
                        // Transform screen point to WPF device independent point
                        PresentationSource source = PresentationSource.FromVisual(this);

                        if (source?.CompositionTarget == null)
                        {   //if this can't be determined, just use the center screen logic
                            v.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        }
                        else
                        {
                            // WindowStartupLocation.CenterScreen sometimes put window out of screen in multi monitor environment
                            v.WindowStartupLocation = WindowStartupLocation.Manual;
                            Matrix m  = source.CompositionTarget.TransformToDevice;
                            double dx = m.M11;
                            double dy = m.M22;
                            Point  locationFromScreen = new Point(
                                screen.Bounds.X + (screen.Bounds.Width - v.Width * dx) / 2,
                                screen.Bounds.Y + (screen.Bounds.Height - (v.SkillResultsGridContainer.MaxHeight + headerHeight) * dy) / 2);
                            Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen);
                            v.Left = targetPoints.X;
                            v.Top  = targetPoints.Y;
                        }
                    }
                    else
                    {
                        v.WindowStartupLocation = WindowStartupLocation.Manual;
                        v.Left = ownedWindows.Max(w => w.Left) + headerHeight;
                        v.Top  = ownedWindows.Max(w => w.Top) + headerHeight;
                    }
                    v.Show();
                }
            }
        }
Exemplo n.º 2
0
 public SkillBreakdownView(SkillBreakdownViewModel viewModel)
 {
     ViewModel = viewModel;
     InitializeComponent();
 }