Dreamine.UI.Wpf.Controls
1.0.1
Dreamine.UI.Wpf.Controls 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreamineListBox.cs
이 파일의 문서화 페이지로 가기
1
using
System.Windows;
2
using
System.Windows.Controls;
3
using
System.Windows.Controls.Primitives;
4
using
System.Windows.Input;
5
6
namespace
Dreamine.UI.Wpf.Controls
7
{
16
public
class
DreamineListBox
: ListBox
17
{
26
static
DreamineListBox
()
27
{
28
// \brief Default style key override (one-time per type)
29
DefaultStyleKeyProperty.OverrideMetadata(typeof(
DreamineListBox
),
30
new
FrameworkPropertyMetadata(typeof(
DreamineListBox
)));
31
32
// \brief Merge style dictionary once
33
var uri =
new
Uri(
"/Dreamine.UI.Wpf.Themes;component/DreamineListBoxStyle.xaml"
, UriKind.RelativeOrAbsolute);
34
35
if
(Application.Current !=
null
)
36
{
37
bool
alreadyAdded = Application.Current.Resources.MergedDictionaries
38
.OfType<ResourceDictionary>()
39
.Any(x => x.Source !=
null
&& x.Source.Equals(uri));
40
41
if
(!alreadyAdded)
42
{
43
var dict =
new
ResourceDictionary { Source = uri };
44
Application.Current.Resources.MergedDictionaries.Add(dict);
45
}
46
}
47
}
48
57
public
DreamineListBox
()
58
{
59
TryMergeStyleOnce
();
60
}
61
70
private
static
void
TryMergeStyleOnce
()
71
{
72
var app = Application.Current;
73
if
(app ==
null
)
74
return
;
75
76
var uri =
new
Uri(
"/Dreamine.UI.Wpf.Themes;component/DreamineListBoxStyle.xaml"
, UriKind.RelativeOrAbsolute);
77
78
bool
alreadyAdded =
79
app.Resources.MergedDictionaries
80
.OfType<ResourceDictionary>()
81
.Any(x => x.Source !=
null
&& x.Source.Equals(uri));
82
83
if
(!alreadyAdded)
84
{
85
var dict =
new
ResourceDictionary { Source = uri };
86
app.Resources.MergedDictionaries.Add(dict);
87
}
88
}
89
90
99
public
static
readonly DependencyProperty
CommandProperty
=
100
DependencyProperty.RegisterAttached(
101
"Command"
,
102
typeof(ICommand),
103
typeof(
DreamineListBox
),
104
new
PropertyMetadata(
null
,
OnCommandChanged
));
105
114
public
static
readonly DependencyProperty
CommandParameterProperty
=
115
DependencyProperty.RegisterAttached(
116
"CommandParameter"
,
117
typeof(
object
),
118
typeof(
DreamineListBox
),
119
new
PropertyMetadata(
null
));
120
129
public
static
readonly DependencyProperty
CommandTriggerNameProperty
=
130
DependencyProperty.RegisterAttached(
131
"CommandTriggerName"
,
132
typeof(
string
),
133
typeof(
DreamineListBox
),
134
new
PropertyMetadata(
null
));
135
168
public
static
void
SetCommandTriggerName
(DependencyObject obj,
string
value)
169
=> obj.SetValue(
CommandTriggerNameProperty
, value);
170
211
public
static
string
GetCommandTriggerName
(DependencyObject obj)
212
=> (string)obj.GetValue(
CommandTriggerNameProperty
);
213
246
public
static
void
SetCommand
(DependencyObject obj, ICommand value) => obj.SetValue(
CommandProperty
, value);
247
288
public
static
ICommand
GetCommand
(DependencyObject obj) => (ICommand)obj.GetValue(
CommandProperty
);
289
322
public
static
void
SetCommandParameter
(DependencyObject obj,
object
value)
323
=> obj.SetValue(
CommandParameterProperty
, value);
324
357
public
static
object
GetCommandParameter
(DependencyObject obj)
358
=> obj.GetValue(
CommandParameterProperty
);
359
392
private
static
void
OnCommandChanged
(DependencyObject d, DependencyPropertyChangedEventArgs e)
393
{
394
if
(d is UIElement element)
395
{
396
// 마우스 클릭
397
element.AddHandler(UIElement.PreviewMouseUpEvent,
new
MouseButtonEventHandler((s, e) =>
398
{
399
TryExecuteCommand
(d,
"PreviewMouseUp"
, e);
400
}),
true
);
401
element.AddHandler(Control.MouseDoubleClickEvent,
new
MouseButtonEventHandler((s, e) =>
402
{
403
TryExecuteCommand
(d,
"MouseDoubleClick"
, e);
404
}),
true
);
405
406
// 키보드 입력
407
element.AddHandler(UIElement.PreviewKeyDownEvent,
new
KeyEventHandler((s, e) =>
408
{
409
TryExecuteCommand
(d,
"PreviewKeyUp"
, e);
410
}),
true
);
411
412
element.AddHandler(UIElement.TouchUpEvent,
new
EventHandler<TouchEventArgs>((s, e) =>
413
{
414
TryExecuteCommand(d,
"TouchUp"
, e);
415
}));
416
417
element.AddHandler(ButtonBase.ClickEvent,
new
RoutedEventHandler((s, e) =>
418
{
419
TryExecuteCommand
(d,
"Click"
, e);
420
}));
421
}
422
}
423
456
private
static
void
TryExecuteCommand
(DependencyObject d,
string
eventName, RoutedEventArgs eventArgs)
457
{
458
var rawTrigger =
GetCommandTriggerName
(d);
459
if
(
string
.IsNullOrEmpty(rawTrigger))
460
return
;
461
462
var triggerList = rawTrigger.Split(
','
)
463
.Select(x => x.Trim())
464
.Where(x => !
string
.IsNullOrEmpty(x));
465
466
if
(!triggerList.Contains(eventName, StringComparer.OrdinalIgnoreCase))
467
return
;
468
469
var command =
GetCommand
(d);
470
var parameter =
GetCommandParameter
(d) ?? eventArgs;
471
472
if
(command?.CanExecute(parameter) ==
true
)
473
command.Execute(parameter);
474
}
475
}
476
}
Dreamine.UI.Wpf.Controls
Definition
DreamineCheckSelector.xaml.cs:6
Dreamine.UI.Wpf.Controls.DreamineListBox.CommandParameterProperty
static readonly DependencyProperty CommandParameterProperty
Definition
DreamineListBox.cs:114
Dreamine.UI.Wpf.Controls.DreamineListBox.GetCommandParameter
static object GetCommandParameter(DependencyObject obj)
Definition
DreamineListBox.cs:357
Dreamine.UI.Wpf.Controls.DreamineListBox.TryExecuteCommand
static void TryExecuteCommand(DependencyObject d, string eventName, RoutedEventArgs eventArgs)
Definition
DreamineListBox.cs:456
Dreamine.UI.Wpf.Controls.DreamineListBox.CommandTriggerNameProperty
static readonly DependencyProperty CommandTriggerNameProperty
Definition
DreamineListBox.cs:129
Dreamine.UI.Wpf.Controls.DreamineListBox.TryMergeStyleOnce
static void TryMergeStyleOnce()
Definition
DreamineListBox.cs:70
Dreamine.UI.Wpf.Controls.DreamineListBox.SetCommand
static void SetCommand(DependencyObject obj, ICommand value)
Definition
DreamineListBox.cs:246
Dreamine.UI.Wpf.Controls.DreamineListBox.DreamineListBox
DreamineListBox()
Definition
DreamineListBox.cs:57
Dreamine.UI.Wpf.Controls.DreamineListBox.OnCommandChanged
static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Definition
DreamineListBox.cs:392
Dreamine.UI.Wpf.Controls.DreamineListBox.SetCommandTriggerName
static void SetCommandTriggerName(DependencyObject obj, string value)
Definition
DreamineListBox.cs:168
Dreamine.UI.Wpf.Controls.DreamineListBox.GetCommandTriggerName
static string GetCommandTriggerName(DependencyObject obj)
Definition
DreamineListBox.cs:211
Dreamine.UI.Wpf.Controls.DreamineListBox.GetCommand
static ICommand GetCommand(DependencyObject obj)
Definition
DreamineListBox.cs:288
Dreamine.UI.Wpf.Controls.DreamineListBox.SetCommandParameter
static void SetCommandParameter(DependencyObject obj, object value)
Definition
DreamineListBox.cs:322
Dreamine.UI.Wpf.Controls.DreamineListBox.CommandProperty
static readonly DependencyProperty CommandProperty
Definition
DreamineListBox.cs:99
Dreamine.UI.Wpf.Controls.DreamineListBox.DreamineListBox
static DreamineListBox()
Definition
DreamineListBox.cs:26
Controls
DreamineListBox.cs
다음에 의해 생성됨 :
1.17.0