Dreamine.MVVM.Wpf 1.0.3
Dreamine.MVVM.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
WindowStateService.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.MVVM.Interfaces.Windows;
2using System;
3using System.Collections.Concurrent;
4
5namespace Dreamine.MVVM.Wpf
6{
23 public sealed class WindowStateService : IWindowStateService
24 {
33 private readonly ConcurrentDictionary<string, bool> _states = new();
34
43 public event EventHandler<WindowStateChangedEventArgs>? StateChanged;
44
69 public bool IsOpen(string windowKey)
70 {
71 ValidateWindowKey(windowKey);
72
73 return _states.TryGetValue(windowKey, out bool isOpen) && isOpen;
74 }
75
92 public void MarkOpened(string windowKey)
93 {
94 SetState(windowKey, true);
95 }
96
113 public void MarkClosed(string windowKey)
114 {
115 SetState(windowKey, false);
116 }
117
142 private void SetState(string windowKey, bool isOpen)
143 {
144 ValidateWindowKey(windowKey);
145
146 _states[windowKey] = isOpen;
147 StateChanged?.Invoke(this, new WindowStateChangedEventArgs(windowKey, isOpen));
148 }
149
174 private static void ValidateWindowKey(string windowKey)
175 {
176 if (string.IsNullOrWhiteSpace(windowKey))
177 {
178 throw new ArgumentException("Window key must not be empty.", nameof(windowKey));
179 }
180 }
181 }
182}
EventHandler< WindowStateChangedEventArgs >? StateChanged
static void ValidateWindowKey(string windowKey)
readonly ConcurrentDictionary< string, bool > _states
void SetState(string windowKey, bool isOpen)