Dreamine.UI.Wpf.Controls 1.0.1
Dreamine.UI.Wpf.Controls 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineRadioButton.cs
이 파일의 문서화 페이지로 가기
1using System.Windows;
2using System.Windows.Controls;
3using System.Windows.Controls.Primitives;
4using System.Windows.Input;
5
7{
16 public class DreamineRadioButton : RadioButton
17 {
27 {
28 DefaultStyleKeyProperty.OverrideMetadata(typeof(DreamineRadioButton),
29 new FrameworkPropertyMetadata(typeof(DreamineRadioButton)));
30
31 var uri = new Uri("/Dreamine.UI.Wpf.Themes;component/DreamineRadioButtonStyle.xaml", UriKind.RelativeOrAbsolute);
32
33 if (Application.Current != null)
34 {
35 bool alreadyAdded = Application.Current.Resources.MergedDictionaries
36 .OfType<ResourceDictionary>()
37 .Any(x => x.Source != null && x.Source.Equals(uri));
38
39 if (!alreadyAdded)
40 {
41 var dict = new ResourceDictionary { Source = uri };
42 Application.Current.Resources.MergedDictionaries.Add(dict);
43 }
44 }
45 }
46
55 public new static readonly DependencyProperty CommandProperty =
56 DependencyProperty.RegisterAttached(
57 "Command",
58 typeof(ICommand),
59 typeof(DreamineRadioButton),
60 new PropertyMetadata(null, OnCommandChanged));
61
70 public new static readonly DependencyProperty CommandParameterProperty =
71 DependencyProperty.RegisterAttached(
72 "CommandParameter",
73 typeof(object),
74 typeof(DreamineRadioButton),
75 new PropertyMetadata(null));
76
85 public static readonly DependencyProperty CommandTriggerNameProperty =
86 DependencyProperty.RegisterAttached(
87 "CommandTriggerName",
88 typeof(string),
89 typeof(DreamineRadioButton),
90 new PropertyMetadata(null));
91
124 public static void SetCommandTriggerName(DependencyObject obj, string value)
125 => obj.SetValue(CommandTriggerNameProperty, value);
126
167 public static string GetCommandTriggerName(DependencyObject obj)
168 => (string)obj.GetValue(CommandTriggerNameProperty);
169
202 public static void SetCommand(DependencyObject obj, ICommand value) => obj.SetValue(CommandProperty, value);
203
244 public static ICommand GetCommand(DependencyObject obj) => (ICommand)obj.GetValue(CommandProperty);
245
278 public static void SetCommandParameter(DependencyObject obj, object value)
279 => obj.SetValue(CommandParameterProperty, value);
280
313 public static object GetCommandParameter(DependencyObject obj)
314 => obj.GetValue(CommandParameterProperty);
315
348 private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
349 {
350 if (d is UIElement element)
351 {
352 element.AddHandler(UIElement.PreviewMouseUpEvent, new MouseButtonEventHandler((s, e) =>
353 {
354 TryExecuteCommand(d, "PreviewMouseUp", e);
355 }), true);
356
357 element.AddHandler(Control.MouseDoubleClickEvent, new MouseButtonEventHandler((s, e) =>
358 {
359 TryExecuteCommand(d, "MouseDoubleClick", e);
360 }), true);
361
362 element.AddHandler(UIElement.PreviewKeyDownEvent, new KeyEventHandler((s, e) =>
363 {
364 TryExecuteCommand(d, "PreviewKeyUp", e);
365 }), true);
366
367 element.AddHandler(UIElement.TouchUpEvent, new EventHandler<TouchEventArgs>((s, e) =>
368 {
369 TryExecuteCommand(d, "TouchUp", e);
370 }));
371
372 element.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler((s, e) =>
373 {
374 TryExecuteCommand(d, "Click", e);
375 }));
376 }
377 }
378
411 private static void TryExecuteCommand(DependencyObject d, string eventName, RoutedEventArgs eventArgs)
412 {
413 var rawTrigger = GetCommandTriggerName(d);
414 if (string.IsNullOrEmpty(rawTrigger))
415 return;
416
417 var triggerList = rawTrigger.Split(',')
418 .Select(x => x.Trim())
419 .Where(x => !string.IsNullOrEmpty(x));
420
421 if (!triggerList.Contains(eventName, StringComparer.OrdinalIgnoreCase))
422 return;
423
424 var command = GetCommand(d);
425 var parameter = GetCommandParameter(d) ?? eventArgs;
426
427 if (command?.CanExecute(parameter) == true)
428 command.Execute(parameter);
429 }
430 }
431}
static void SetCommandTriggerName(DependencyObject obj, string value)
static object GetCommandParameter(DependencyObject obj)
static readonly DependencyProperty CommandTriggerNameProperty
static string GetCommandTriggerName(DependencyObject obj)
static new readonly DependencyProperty CommandProperty
static void TryExecuteCommand(DependencyObject d, string eventName, RoutedEventArgs eventArgs)
static new readonly DependencyProperty CommandParameterProperty
static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
static void SetCommand(DependencyObject obj, ICommand value)
static void SetCommandParameter(DependencyObject obj, object value)
static ICommand GetCommand(DependencyObject obj)