SampleCrossUi.Shared 1.0.0.0
SampleCrossUi.Shared 사용 방법을 보여 주는 예제 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
ControlsViewModel.cs
이 파일의 문서화 페이지로 가기
1using System;
2using System.Collections.ObjectModel;
3using Dreamine.MVVM.Attributes;
4using Dreamine.MVVM.Interfaces;
5using Dreamine.MVVM.ViewModels;
6
8
17public class ControlsDemoRow
18{
27 public int No { get; set; }
36 public string Name { get; set; } = string.Empty;
45 public string Status { get; set; } = string.Empty;
46}
47
56public enum DemoStatus
57{
66 [System.ComponentModel.Description("대기 중")]
76 [System.ComponentModel.Description("실행 중")]
86 [System.ComponentModel.Description("오류 발생")]
88}
89
98public partial class ControlsViewModel : ViewModelBase, IActivatable, IVisibilityAware
99{
100 // ── ViewSwitcher.NotifyShown/NotifyHidden 데모 ──────────
109 [DreamineProperty]
110 private string _activationLog = "(탭을 떠났다가 다시 들어오면 로그가 쌓입니다)";
111
120 void IActivatable.Activate() => ActivationLog = $"[{DateTime.Now:HH:mm:ss}] Activate()";
129 void IActivatable.Deactivate() => ActivationLog = $"[{DateTime.Now:HH:mm:ss}] Deactivate()";
138 void IVisibilityAware.OnShown() => ActivationLog = $"[{DateTime.Now:HH:mm:ss}] OnShown()";
147 void IVisibilityAware.OnHidden() => ActivationLog = $"[{DateTime.Now:HH:mm:ss}] OnHidden()";
148
149
158 [DreamineEvent]
160
161 // ── Button ────────────────────────────────────────────
170 public int ClickCount => Event.ClickCount;
171
180 public ObservableCollection<string> ActivityLog => Event.ActivityLog;
181
190 [DreamineCommand("Event.ClickMe")]
191 private partial void ClickMe();
192
193 // ── CheckBox (순수 UI 상태; 커맨드 로직 없음) ───────────
202 [DreamineProperty]
203 private bool _check1 = true;
204
213 [DreamineProperty]
214 private bool _check2;
215
224 [DreamineProperty]
225 private bool _check3;
226
227 // ── RadioButton ───────────────────────────────────────
236 public string SelectedRadio => Event.SelectedRadio;
237
246 public RelayCommand<string> SelectRadioCommand { get; }
247
248 // ── CheckLed ──────────────────────────────────────────
257 public bool LedIsOn => Event.LedIsOn;
266 public bool LedIsPulse => Event.LedIsPulse;
267
276 [DreamineCommand("Event.ToggleLed")]
277 private partial void ToggleLed();
278
287 [DreamineCommand("Event.TogglePulse")]
288 private partial void TogglePulse();
289
290 // ── TextBox / PasswordBox ─────────────────────────────
299 public string TextInput
300 {
301 get => Event.TextInput;
302 set
303 {
304 if (Event.TextInput == value) return;
305 Event.TextInput = value;
306 OnPropertyChanged(nameof(TextInput));
307 }
308 }
309
318 public string Password
319 {
320 get => Event.Password;
321 set
322 {
323 if (Event.Password == value) return;
324 Event.Password = value;
325 OnPropertyChanged(nameof(Password));
326 }
327 }
328
337 [DreamineCommand("Event.ClearText")]
338 private partial void ClearText();
339
348 [DreamineCommand("Event.ClearPassword")]
349 private partial void ClearPassword();
350
351 // ── ComboBox (순수 UI 상태) ─────────────────────────────
360 public ObservableCollection<string> FruitItems { get; } =
361 new() { "Apple", "Banana", "Cherry", "Grape", "Mango", "Melon" };
362
371 [DreamineProperty]
372 private string _selectedFruit = "Cherry";
373
374 // ── Expander (순수 UI 상태) ─────────────────────────────
383 [DreamineProperty]
384 private bool _isExpanded = true;
385
386 // ── TimeSpinner (WPF-only; ignored by WinForms; 순수 UI 상태) ──
395 [DreamineProperty]
396 private TimeSpan _time = new(9, 30, 0);
397
398 // ── DataGrid (정적 시연 데이터) ─────────────────────────
407 public ObservableCollection<ControlsDemoRow> GridRows { get; } = new()
408 {
409 new ControlsDemoRow { No = 1, Name = "Device A", Status = "Running" },
410 new ControlsDemoRow { No = 2, Name = "Device B", Status = "Stopped" },
411 new ControlsDemoRow { No = 3, Name = "Device C", Status = "Running" },
412 new ControlsDemoRow { No = 4, Name = "Device D", Status = "Error" },
413 };
414
415 // ── ListBox 활성화(더블클릭) ───────────────────────────
424 public RelayCommand<string> ListBoxActivatedCommand { get; }
425
426 // ── NumericRangeBehavior (순수 UI 상태) ─────────────────
435 [DreamineProperty]
436 private double _numericInput = 50;
437
438 // ── Status ────────────────────────────────────────────
447 public string StatusMessage => Event.StatusMessage;
448
449 // ── Converters 탭 전용 샘플 데이터 ──────────────────────
458 [DreamineProperty]
459 private DemoStatus _demoEnum = DemoStatus.Running;
460
469 public DateTime DemoDateTime { get; } = DateTime.Now;
470
479 [DreamineProperty]
480 private string _demoFlagString = "1";
481
490 [DreamineProperty]
491 private object _demoNullable = null!;
492
501 public string DemoWireName => "Wire-001";
510 public string DemoEmName => "EM-205";
511
529 {
530 _event = @event;
531
532 Event.Changed += (_, _) =>
533 {
534 OnPropertyChanged(nameof(ClickCount));
535 OnPropertyChanged(nameof(StatusMessage));
536 OnPropertyChanged(nameof(SelectedRadio));
537 OnPropertyChanged(nameof(LedIsOn));
538 OnPropertyChanged(nameof(LedIsPulse));
539 OnPropertyChanged(nameof(TextInput));
540 OnPropertyChanged(nameof(Password));
541 };
542
543 SelectRadioCommand = new RelayCommand<string>(option => Event.SelectRadio(option));
544 ListBoxActivatedCommand = new RelayCommand<string>(item => Event.ListBoxActivated(item));
545 }
546}
ObservableCollection< ControlsDemoRow > GridRows