{"action":"created","issue":{"url":"https://api.github.com/repos/anakic/Jot/issues/3","repository_url":"https://api.github.com/repos/anakic/Jot","labels_url":"https://api.github.com/repos/anakic/Jot/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/anakic/Jot/issues/3/comments","events_url":"https://api.github.com/repos/anakic/Jot/issues/3/events","html_url":"https://github.com/anakic/Jot/issues/3","id":181686054,"number":3,"title":"Maximize window on correct monitor","user":{"login":"Marv51","id":471338,"avatar_url":"https://avatars.githubusercontent.com/u/471338?v=3","gravatar_id":"","url":"https://api.github.com/users/Marv51","html_url":"https://github.com/Marv51","followers_url":"https://api.github.com/users/Marv51/followers","following_url":"https://api.github.com/users/Marv51/following{/other_user}","gists_url":"https://api.github.com/users/Marv51/gists{/gist_id}","starred_url":"https://api.github.com/users/Marv51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marv51/subscriptions","organizations_url":"https://api.github.com/users/Marv51/orgs","repos_url":"https://api.github.com/users/Marv51/repos","events_url":"https://api.github.com/users/Marv51/events{/privacy}","received_events_url":"https://api.github.com/users/Marv51/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-07T14:39:18Z","updated_at":"2016-10-12T19:11:17Z","closed_at":null,"body":"If a window is maximized it appears to not get restored on the correct monitor. In my testing the window always gets restored on the primary screen.\r\n\r\nAccording to http://mostlytech.blogspot.de/2008/01/maximizing-wpf-window-to-second-monitor.html and https://social.msdn.microsoft.com/Forums/vstudio/en-US/2ca2fab6-b349-4c08-915f-373c71bd636a/show-and-maximize-wpf-window-on-a-specific-screen?forum=wpf\r\nThe WindowState Property should be applied after the window loaded event was fired.\r\n\r\nMoving the call to .Apply() to the LoadedEvent handler on the window fixes this problem.\r\n\r\nBut maybe there could be a more elegant solution?\r\n\r\nIt is getting quite complicated, my \"minimal\" window setup:\r\n```\r\npublic partial class ProjectView : Window\r\n    {\r\n        private TrackingConfiguration JotTracker;\r\n\r\n        public ProjectView()\r\n        {\r\n            InitializeComponent();\r\n\r\n            JotTracker = StateTrackerService.Tracker.Configure(this);\r\n            JotTracker.ApplyingProperty += StateTrackerService.StateConfig_ApplyingProperty;\r\n            JotTracker.IdentifyAs(\"ProjectView\")\r\n               .AddProperties<ProjectView>(w => w.Height, w => w.Width, w => w.Left, w => w.Top, w => w.WindowState)\r\n               .RegisterPersistTrigger(nameof(Closed));\r\n\r\n                Loaded += ProjectView_Loaded;\r\n        }\r\n\r\n        private void ProjectView_Loaded(object sender, RoutedEventArgs e)\r\n        {\r\n            JotTracker.Apply();\r\n        }\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/anakic/Jot/issues/comments/253309183","html_url":"https://github.com/anakic/Jot/issues/3#issuecomment-253309183","issue_url":"https://api.github.com/repos/anakic/Jot/issues/3","id":253309183,"user":{"login":"anakic","id":9460757,"avatar_url":"https://avatars.githubusercontent.com/u/9460757?v=3","gravatar_id":"","url":"https://api.github.com/users/anakic","html_url":"https://github.com/anakic","followers_url":"https://api.github.com/users/anakic/followers","following_url":"https://api.github.com/users/anakic/following{/other_user}","gists_url":"https://api.github.com/users/anakic/gists{/gist_id}","starred_url":"https://api.github.com/users/anakic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anakic/subscriptions","organizations_url":"https://api.github.com/users/anakic/orgs","repos_url":"https://api.github.com/users/anakic/repos","events_url":"https://api.github.com/users/anakic/events{/privacy}","received_events_url":"https://api.github.com/users/anakic/received_events","type":"User","site_admin":false},"created_at":"2016-10-12T19:11:17Z","updated_at":"2016-10-12T19:11:17Z","body":"@Marv51 I just noticed the \"if a window is maximized\" part. Yeah, just checked, it will always get restored to the main screen. Been working with WPF for years and never noticed that issue...\r\n\r\nSomeone in the comments of the link you sent suggested using the `windows.SourceInitialized` event, as this removes the flicker (I checked, it does). \r\n\r\nOne thing you can do is move all the Jot code from the constructor to the SourceInitialized eventhandler. That way it's not scattered about. It's only executed once per window (I'm guessing) anyway.\r\n\r\nAnother solution might be to make a static helper method like SetUpJot(Window window, StateTracker tracker). You could call this method from the constructor of any window. The method would subscribe to the windows's `SourceInitialized` event and set up tracking for it. You could pass window.Name to IdentifyAs to identify the window.\r\n\r\nIf you're using an IOC container, you could make this a post build step, so that all windows (that are created via IOC) get this behavior out of the box.\r\n\r\nAny of this make sense?"}}
{"actor":{"display_login":"anakic"}}