SampleCrossUi.Wpf 1.0.0.0
SampleCrossUi.Wpf 사용 방법을 보여 주는 예제 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
PopupEvent.cs
이 파일의 문서화 페이지로 가기
1using System;
2using System.Windows;
3using System.Windows.Controls;
4using System.Windows.Media;
5using Dreamine.UI.Abstractions.Popup;
6using Dreamine.UI.Wpf.Behaviors;
7using Dreamine.UI.Wpf.Controls.MessageBox;
8using Dreamine.UI.Wpf.Controls.ViewRegion;
9using Microsoft.Xaml.Behaviors;
11
13
22public sealed class PopupEvent
23{
32 private readonly IPopupService _popupService;
33
58 public PopupEvent(IPopupService popupService)
59 {
60 _popupService = popupService ?? throw new ArgumentNullException(nameof(popupService));
61 }
62
71 public string LastResult { get; private set; } = "-";
72
81 public event EventHandler? Changed;
82
99 private void SetLastResult(string value)
100 {
101 LastResult = value;
102 Changed?.Invoke(this, EventArgs.Empty);
103 }
104
113 public void ShowMessageBox()
114 {
115 DreamineMessageBox.ShowAsync(
116 "DreamineMessageBox 데모입니다.\n버튼을 클릭하거나 기다리면 자동으로 닫힙니다.",
117 "MessageBox Demo",
118 autoClick: MessageBoxResult.OK,
119 autoClickDelaySeconds: 5,
120 callback: r => SetLastResult($"MessageBox → {r}"));
121 }
122
131 public void ShowBlinkOk()
132 {
133 _ = ShowBlinkOkAsync();
134 }
135
144 public void ShowBlinkAlarm()
145 {
147 }
148
157 public void OpenAsWindow()
158 {
159 var info = ViewLoader.LoadViewWithViewModel(
160 typeof(PopupView).FullName!,
161 useSingletonView: true);
162
163 PopupWindowManager.Instance.CreatePopup(
164 "PopupViewWindow",
165 info,
166 popupWidth: 420,
167 popupHeight: 460,
168 centerOnScreen: true);
169
170 if (PopupWindowManager.Instance.Windows.TryGetValue("PopupViewWindow", out var popup))
171 {
172 // PopupWindowManager가 만드는 창은 WindowStyle=None이라 제목줄/닫기 버튼이 없다.
173 // 매번 새 Window+View가 만들어지므로, 매 호출마다 직접 타이틀바(드래그+닫기)를 씌워준다.
174 WrapWithTitleBar(popup);
175
176 PopupWindowManager.Instance.Show("PopupViewWindow");
177 popup.Activate();
178 popup.Focus();
179 }
180 else
181 {
182 PopupWindowManager.Instance.Show("PopupViewWindow");
183 }
184 }
185
202 private static void WrapWithTitleBar(Window popup)
203 {
204 if (popup.Content is not UIElement originalContent)
205 return;
206
207 popup.Content = null;
208
209 var root = new Grid();
210 root.RowDefinitions.Add(new RowDefinition { Height = new GridLength(32) });
211 root.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
212
213 var titleBar = new Border { Background = new SolidColorBrush(Color.FromRgb(0x0D, 0x1B, 0x3E)) };
214 Interaction.GetBehaviors(titleBar).Add(new WindowDragBehavior());
215
216 var closeButton = new Button
217 {
218 Content = "✕",
219 Width = 32,
220 Height = 32,
221 HorizontalAlignment = HorizontalAlignment.Right,
222 Background = Brushes.Transparent,
223 BorderThickness = new Thickness(0),
224 Foreground = Brushes.White
225 };
226 closeButton.Click += (_, _) => popup.Close();
227 titleBar.Child = closeButton;
228
229 Grid.SetRow(titleBar, 0);
230 Grid.SetRow(originalContent, 1);
231 root.Children.Add(titleBar);
232 root.Children.Add(originalContent);
233
234 popup.Content = root;
235 }
236
253 private async System.Threading.Tasks.Task ShowBlinkOkAsync()
254 {
255 var result = await _popupService.ShowBlinkAsync(
256 Application.Current.MainWindow,
257 new BlinkPopupOptions
258 {
259 Title = "작업 완료",
260 Message = "작업이 성공적으로 완료되었습니다.",
261 UseBlink = false,
262 OkText = "확인",
263 IsModal = true
264 });
265 SetLastResult($"BlinkPopup(OK) → {result}");
266 }
267
284 private async System.Threading.Tasks.Task ShowBlinkAlarmAsync()
285 {
286 var result = await _popupService.ShowBlinkAsync(
287 Application.Current.MainWindow,
288 new BlinkPopupOptions
289 {
290 Title = "⚠ ALARM",
291 Message = "설비 이상이 감지되었습니다.\n운영자 확인이 필요합니다.",
292 UseBlink = true,
293 BlinkIntervalMs = 400,
294 Color1 = Color.FromRgb(180, 30, 30),
295 Color2 = Color.FromRgb(80, 10, 10),
296 Opacity1 = 1.0,
297 Opacity2 = 0.6,
298 OkText = "확인",
299 CancelText = "취소",
300 IsModal = true
301 });
302 SetLastResult($"BlinkPopup(Alarm) → {result}");
303 }
304}
async System.Threading.Tasks.Task ShowBlinkAlarmAsync()
PopupEvent(IPopupService popupService)
Definition PopupEvent.cs:58
async System.Threading.Tasks.Task ShowBlinkOkAsync()
static void WrapWithTitleBar(Window popup)
readonly IPopupService _popupService
Definition PopupEvent.cs:32