private IWindowView GetOrCreateWindowView( IWindowContent windowContent, IWindowSettings setting, IWindowView ownerWindow, bool isCreate, Type windowType = null) { this.CheckAndRemoveInvalidCache(); var needCreateView = this._windowCaches.ContainsKey(windowContent) == false || isCreate; if (needCreateView) { this.CreateWindowView(windowContent, setting, windowType); } var window = this._windowCaches[windowContent]; if (ownerWindow != null) { window.View.SetOwner(ownerWindow); } return(window.View); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this._source = PresentationSource.FromVisual(this) as HwndSource; if (this._source == null) { return; } this._source.AddHook(this.WndProc); if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } if (this.IsRestoringWindowPlacement) { this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; if (placement.showCmd == ShowWindowFlags.SW_MINIMIZE || placement.showCmd == ShowWindowFlags.SW_SHOWMINIMIZED) { placement.showCmd = ShowWindowFlags.SW_RESTORE; } User32.SetWindowPlacement(this._source.Handle, ref placement); } } }
protected override void OnSourceInitialized(EventArgs e) { semaphore = new MultipleControl(this); if (!semaphore.IsCreate()) { // 他のプロセスが先にセマフォを作っていた this.Visibility = Visibility.Collapsed; return; // プログラム終了 } base.OnSourceInitialized(e); // 外部からウィンドウ設定の保存・復元クラスが与えられていない場合は、既定実装を使用する if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var hwnd = new WindowInteropHelper(this).Handle; var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED) ? SW.SHOWNORMAL : placement.showCmd; NativeMethods.SetWindowPlacement(hwnd, ref placement); } }
protected WindowsHelperWindow(IWindowSettings settings, SizeChangedEventHandler onSizeChanged, EventHandler onLocationChanged) { Settings = settings; _onSizeChanged = onSizeChanged; _onLocationChanged = onLocationChanged; //SizeChanged += _onSizeChanged; //LocationChanged += _onLocationChanged; Loaded += OnLoaded; }
public static void Register(FormWithWindowStateChangeEvent form, IWindowSettings settings, bool initiallyMaximized, ref IContainer?container) { Guard.NotNull(form, nameof(form)); Guard.NotNull(settings, nameof(settings)); if (!form.IsMdiChild) { throw new InvalidOperationException("Form must be an MDI child."); } // Justification for discard: Object registers itself to get disposed along with specified container on Form. _ = new DisposableComponent <TargetWindow>(new TargetWindow(form, settings, initiallyMaximized), ref container); }
private IWindowView CreateWindowView(IWindowContent windowContent, IWindowSettings setting, Type targeType = null) { var modelType = windowContent.GetType(); var windowTypeName = modelType.Name.Replace("ViewModel", string.Empty); // 1. 특정 Window 타입이 없으면 CommonWindow 사용. // 2. 1번이 null 일 경우 캐쉬되어 있는 this._customWindowTypes 에서 windowContent 의 이름을 기준으로 찾아서 사용. // 3. 2번이 null 일 경우 전달 받은 타입 사용. var windowType = (targeType == null ? this._commonWindowType : this._customWindowTypes.FirstOrDefault(w => string.CompareOrdinal(w.Name, windowTypeName) == 0)) ?? targeType; if (windowType == null) { // TODO : need logging return(null); } var windowView = Activator.CreateInstance(windowType) as IWindowView; if (windowView == null) { // TODO : need logging return(null); } var dataContextInfo = windowType.GetProperty("DataContext"); // Window의 DataContext는 View에서 함께 생성한다. var dataContext = dataContextInfo?.GetValue(windowView); // Window의 ViewModel은 반드시 IWindowContext을 상속해야한다. var windowViewModel = dataContext as IWindowContext; if (windowViewModel == null) { // TODO : need logging return(null); } windowViewModel.Setting = setting; windowView.Initialize(setting); this._windowCaches.Add(windowContent, new WindowViewStore { View = windowView, Context = windowViewModel }); windowViewModel.ContentContext = windowContent; return(windowView); }
public TargetWindow(FormWithWindowStateChangeEvent form, IWindowSettings settings, bool initiallyMaximized) { Guard.NotNull(form, nameof(form)); Guard.NotNull(settings, nameof(settings)); this.form = form; this.settings = settings; form.LocationChanged += FormOnLocationChanged; form.SizeChanged += FormOnSizeChanged; form.WindowStateChanged += FormOnWindowStateChanged; UpdateLayoutFromSettings(initiallyMaximized); }
public TargetWindow([NotNull] FormWithWindowStateChangeEvent form, [NotNull] IWindowSettings settings, bool initiallyMaximized) { Guard.NotNull(form, nameof(form)); Guard.NotNull(settings, nameof(settings)); this.form = form; this.settings = settings; form.LocationChanged += FormOnLocationChanged; form.SizeChanged += FormOnSizeChanged; form.WindowStateChanged += FormOnWindowStateChanged; UpdateLayoutFromSettings(initiallyMaximized); }
public void Initialize(IWindowSettings settings) { this.Settings = settings; this.ResizeMode = settings.ResizeMode.GetEnum <ResizeMode>(); this.SizeToContent = settings.SizeToContent.GetEnum <SizeToContent>(); this.WindowState = settings.State.GetEnum <WindowState>(); this._chrome = new WindowChrome { CaptionHeight = 0, CornerRadius = new CornerRadius(), GlassFrameThickness = new Thickness(), ResizeBorderThickness = new Thickness(5) }; WindowChrome.SetWindowChrome(this, this._chrome); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this.source = PresentationSource.FromVisual(this) as HwndSource; if (this.source == null) { return; } this.systemDpi = this.GetSystemDpi() ?? Dpi.Default; if (PerMonitorDpi.IsSupported) { this.currentDpi = this.source.GetDpi(); this.ChangeDpi(this.currentDpi); this.source.AddHook(this.WndProc); } else { this.currentDpi = this.systemDpi; } if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } if (this.IsRestoringWindowPlacement) { this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED ? SW.SHOWNORMAL : placement.showCmd); NativeMethods.SetWindowPlacement(this.source.Handle, ref placement); } } }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); // 外部からウィンドウ設定の保存・復元クラスが与えられていない場合は、既定実装を使用する if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var hwnd = new WindowInteropHelper(this).Handle; var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED) ? SW.SHOWNORMAL : placement.showCmd; NativeMethods.SetWindowPlacement(hwnd, ref placement); } }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); // 外部からウィンドウ設定の保存・復元クラスが与えられていない場合は、既定実装を使用する if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var hwnd = new WindowInteropHelper(this).Handle; var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED) ? SW.SHOWNORMAL : placement.showCmd; NativeMethods.SetWindowPlacement(hwnd, ref placement); } }
public SettingsWindow(IWindowSettings settings, SizeChangedEventHandler onSizeChanged, EventHandler onLocationChanged) : base(settings, onSizeChanged, onLocationChanged) { InitializeComponent(); }
public IWindowView GetOrCreateWindow(IWindowContent windowContent, IWindowSettings setting, IWindowContent ownerViewModel = null, bool isCreate = false) { var ownerWindow = this.GetWindowView(ownerViewModel); return(this.GetOrCreateWindowView(windowContent, setting, ownerWindow, isCreate)); }
public WindowEntry(IWindow window, IWindowSettings settings) { Window = window; Settings = settings; }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this.source = PresentationSource.FromVisual(this) as HwndSource; if (this.source == null) return; this.systemDpi = this.GetSystemDpi() ?? Dpi.Default; if (PerMonitorDpi.IsSupported) { this.currentDpi = this.source.GetDpi(); this.ChangeDpi(this.currentDpi); this.source.AddHook(this.WndProc); } else { this.currentDpi = this.systemDpi; } if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } if (this.IsRestoringWindowPlacement) { this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED ? SW.SHOWNORMAL : placement.showCmd); NativeMethods.SetWindowPlacement(this.source.Handle, ref placement); } } }
public WindowSettingsProvider(Window window, IWindowSettings settings) { this.window = window; this.settings = settings; }