private void Configure(Window view, object viewModel = null) { // without VieWModel we cannot uniquely identify the window if (!(viewModel is IMaintainPosition) || _uiConfiguration == null || !_uiConfiguration.AreWindowLocationsStored) { return; } var windowName = viewModel.GetType().FullName; var screenBounds = DisplayInfo.GetAllScreenBounds(); var hasPlacement = _uiConfiguration.WindowLocations.TryGetValue(windowName, out var placement); if (!hasPlacement || placement.ShowCmd == ShowWindowCommands.Normal && !screenBounds.Contains(placement.NormalPosition)) { view.WindowStartupLocation = view.Owner != null ? WindowStartupLocation.CenterOwner : _uiConfiguration.DefaultWindowStartupLocation; hasPlacement = false; } if (hasPlacement) { view.WindowStartupLocation = WindowStartupLocation.Manual; } // Storage for the event handlers, so we can remove them again EventHandler[] eventHandlers = new EventHandler[3]; // Store Placement eventHandlers[1] = (sender, args) => { // ReSharper disable once InvokeAsExtensionMethod var newPlacement = WindowsExtensions.RetrievePlacement(view); if (newPlacement.ShowCmd == ShowWindowCommands.Hide) { // Ignore return; } Log.Debug().WriteLine("Stored placement {0} for Window {1}", newPlacement.NormalPosition, windowName); _uiConfiguration.WindowLocations[windowName] = newPlacement; }; // Cleanup handlers eventHandlers[2] = (s, e) => { view.LocationChanged -= eventHandlers[1]; view.Closed -= eventHandlers[2]; }; //Initialize handlers eventHandlers[0] = (sender, args) => { if (hasPlacement) { // Make sure the placement is set WindowsExtensions.ApplyPlacement(view, placement); } view.LocationChanged -= eventHandlers[0]; view.LocationChanged += eventHandlers[1]; view.Closed += eventHandlers[2]; }; view.LocationChanged += eventHandlers[0]; }
/// <overloads> /// Initializes a new instance of the <see cref="ImageListBoxItem"/> class.</overloads> /// <summary> /// Initializes a new instance of the <see cref="ImageListBoxItem"/> class with default /// properties.</summary> public ImageListBoxItem() { this._labelTypeface = WindowsExtensions.GetTypeface(this); this._labelEmSize = FontSize; }