Dreamine.UI.Wpf.Controls
1.0.1
Dreamine.UI.Wpf.Controls 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreamineImage.cs
이 파일의 문서화 페이지로 가기
1
using
System;
2
using
System.Linq;
3
using
System.Windows;
4
using
System.Windows.Controls;
5
using
System.Windows.Input;
6
using
System.Windows.Media;
7
8
using
Dreamine.MVVM.Core;
9
10
namespace
Dreamine.UI.Wpf.Controls
11
{
20
public
class
DreamineImage
: Control
21
{
22
23
// Control 클래스에는 이미 BorderThickness, BorderBrush가 있습니다.
24
// CornerRadius는 Control에 없으므로 직접 추가합니다.
33
public
static
readonly DependencyProperty
CornerRadiusProperty
=
34
DependencyProperty.Register(
35
nameof(
CornerRadius
),
36
typeof(
CornerRadius
),
37
typeof(
DreamineImage
),
38
new
FrameworkPropertyMetadata(
new
CornerRadius
(0)));
39
40
// Image의 Source와 같은 역할을 할 프로퍼티를 새로 정의합니다.
49
public
static
readonly DependencyProperty
SourceProperty
=
50
DependencyProperty.Register(
51
nameof(
Source
),
52
typeof(ImageSource),
53
typeof(
DreamineImage
),
54
new
FrameworkPropertyMetadata(
null
));
55
64
public
static
readonly DependencyProperty
FallbackSourceProperty
=
65
DependencyProperty.Register(
66
nameof(
FallbackSource
),
67
typeof(ImageSource),
68
typeof(
DreamineImage
),
69
new
FrameworkPropertyMetadata(
null
));
70
79
public
static
readonly DependencyProperty
ClickCommandProperty
=
80
DependencyProperty.Register(
81
nameof(
ClickCommand
),
82
typeof(ICommand),
83
typeof(
DreamineImage
),
84
new
PropertyMetadata(
null
));
85
94
public
static
readonly DependencyProperty
CommandParameterProperty
=
95
DependencyProperty.Register(
96
nameof(
CommandParameter
),
97
typeof(
object
),
98
typeof(
DreamineImage
),
99
new
PropertyMetadata(
null
));
100
109
public
static
readonly DependencyProperty
IsWindowDragEnabledProperty
=
110
DependencyProperty.Register(
111
nameof(
IsWindowDragEnabled
),
112
typeof(
bool
),
113
typeof(
DreamineImage
),
114
new
PropertyMetadata(
false
));
115
124
public
static
readonly DependencyProperty
IsDoubleClickToggleMaximizeProperty
=
125
DependencyProperty.Register(
126
nameof(
IsDoubleClickToggleMaximize
),
127
typeof(
bool
),
128
typeof(
DreamineImage
),
129
new
PropertyMetadata(
true
));
130
131
// Stretch 속성도 Image에서 가져와서 새로 정의합니다.
140
public
static
readonly DependencyProperty
StretchProperty
=
141
DependencyProperty.Register(
142
nameof(
Stretch
),
143
typeof(
Stretch
),
144
typeof(
DreamineImage
),
145
new
PropertyMetadata(
Stretch
.Uniform));
146
155
public
CornerRadius
CornerRadius
156
{
157
get
=> (
CornerRadius
)GetValue(
CornerRadiusProperty
);
158
set
=> SetValue(
CornerRadiusProperty
, value);
159
}
160
161
// 새로 추가한 Source 프로퍼티
170
public
ImageSource?
Source
171
{
172
get
=> (ImageSource?)GetValue(
SourceProperty
);
173
set
=> SetValue(
SourceProperty
, value);
174
}
175
184
public
ImageSource?
FallbackSource
185
{
186
get
=> (ImageSource?)GetValue(
FallbackSourceProperty
);
187
set
=> SetValue(
FallbackSourceProperty
, value);
188
}
189
198
public
ICommand?
ClickCommand
199
{
200
get
=> (ICommand?)GetValue(
ClickCommandProperty
);
201
set
=> SetValue(
ClickCommandProperty
, value);
202
}
203
212
public
object
?
CommandParameter
213
{
214
get
=> GetValue(
CommandParameterProperty
);
215
set
=> SetValue(
CommandParameterProperty
, value);
216
}
217
226
public
bool
IsWindowDragEnabled
227
{
228
get
=> (bool)GetValue(
IsWindowDragEnabledProperty
);
229
set
=> SetValue(
IsWindowDragEnabledProperty
, value);
230
}
231
240
public
bool
IsDoubleClickToggleMaximize
241
{
242
get
=> (bool)GetValue(
IsDoubleClickToggleMaximizeProperty
);
243
set
=> SetValue(
IsDoubleClickToggleMaximizeProperty
, value);
244
}
245
254
public
Stretch
Stretch
255
{
256
get
=> (
Stretch
)GetValue(
StretchProperty
);
257
set
=> SetValue(
StretchProperty
, value);
258
}
259
268
static
DreamineImage
()
269
{
270
try
271
{
272
273
DefaultStyleKeyProperty.OverrideMetadata(typeof(
DreamineImage
),
274
new
FrameworkPropertyMetadata(typeof(
DreamineImage
)));
275
276
var uri =
new
Uri(
"/Dreamine.UI.Wpf.Themes;component/DreamineImageStyle.xaml"
, UriKind.RelativeOrAbsolute);
277
bool
alreadyAdded = Application.Current.Resources.MergedDictionaries
278
.OfType<ResourceDictionary>()
279
.Any(x => x.Source !=
null
&& x.Source.Equals(uri));
280
281
if
(!alreadyAdded)
282
{
283
var dict =
new
ResourceDictionary {
Source
= uri };
284
Application.Current.Resources.MergedDictionaries.Add(dict);
285
}
286
287
}
288
catch
289
{
290
// 디자이너/테스트 환경 보호
291
}
292
}
293
302
public
DreamineImage
()
303
{
304
PreviewMouseLeftButtonDown +=
OnPreviewMouseLeftButtonDown
;
305
MouseLeftButtonUp +=
OnMouseLeftButtonUp
;
306
MouseMove +=
OnMouseMove
;
307
// WPF Image에는 MouseDoubleClick 이벤트가 없으므로 사용하지 않음.
308
}
309
318
private
Point
_pressPoint
;
327
private
bool
_isDragging
;
328
353
private
void
OnPreviewMouseLeftButtonDown
(
object
sender, MouseButtonEventArgs e)
354
{
355
// 1) 더블클릭 토글 (WPF는 ClickCount로 판별)
356
if
(
IsDoubleClickToggleMaximize
&& e.ClickCount == 2)
357
{
358
var win = Window.GetWindow(
this
);
359
if
(win !=
null
)
360
{
361
try
362
{
363
win.WindowState = win.WindowState == WindowState.Maximized
364
? WindowState.Normal
365
: WindowState.Maximized;
366
e.Handled =
true
;
367
return
;
368
}
369
catch
{
/* 무시 */
}
370
}
371
}
372
373
// 2) 드래그 대비 기준점 기록
374
_pressPoint
= e.GetPosition(
this
);
375
_isDragging
=
false
;
376
CaptureMouse();
377
}
378
411
private
void
OnMouseMove
(
object
sender, MouseEventArgs e)
412
{
413
if
(!
IsWindowDragEnabled
|| e.LeftButton != MouseButtonState.Pressed)
414
return
;
415
416
var p = e.GetPosition(
this
);
417
var dx = Math.Abs(p.X -
_pressPoint
.X);
418
var dy = Math.Abs(p.Y -
_pressPoint
.Y);
419
420
if
(!
_isDragging
&&
421
(dx > SystemParameters.MinimumHorizontalDragDistance ||
422
dy > SystemParameters.MinimumVerticalDragDistance))
423
{
424
_isDragging
=
true
;
425
426
// \note DragMove 직전 캡처 해제 (드래그 씹힘 방지 핵심)
427
try
428
{
429
if
(Mouse.Captured ==
this
)
430
ReleaseMouseCapture();
431
else
432
Mouse.Capture(
null
);
433
}
434
catch
{
/* ignore */
}
435
436
try
437
{
438
var win = Window.GetWindow(
this
);
439
win?.DragMove();
440
}
441
catch
442
{
443
// DragMove 중 예외는 조용히 무시
444
}
445
}
446
}
447
480
private
void
OnMouseLeftButtonUp
(
object
sender, MouseButtonEventArgs e)
481
{
482
ReleaseMouseCapture();
483
484
if
(
_isDragging
)
return
;
// 드래그로 끝난 경우 클릭 아님
485
486
if
(
ClickCommand
?.CanExecute(
CommandParameter
) ==
true
)
487
{
488
try
{
ClickCommand
.Execute(
CommandParameter
); }
catch
{
/* 무시 */
}
489
}
490
}
491
492
}
493
}
Dreamine.UI.Wpf.Controls
Definition
DreamineCheckSelector.xaml.cs:6
Dreamine.UI.Wpf.Controls.DreamineImage.OnMouseLeftButtonUp
void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
Definition
DreamineImage.cs:480
Dreamine.UI.Wpf.Controls.DreamineImage.ClickCommandProperty
static readonly DependencyProperty ClickCommandProperty
Definition
DreamineImage.cs:79
Dreamine.UI.Wpf.Controls.DreamineImage.DreamineImage
DreamineImage()
Definition
DreamineImage.cs:302
Dreamine.UI.Wpf.Controls.DreamineImage.FallbackSource
ImageSource? FallbackSource
Definition
DreamineImage.cs:185
Dreamine.UI.Wpf.Controls.DreamineImage.CommandParameter
object? CommandParameter
Definition
DreamineImage.cs:213
Dreamine.UI.Wpf.Controls.DreamineImage.IsWindowDragEnabled
bool IsWindowDragEnabled
Definition
DreamineImage.cs:227
Dreamine.UI.Wpf.Controls.DreamineImage.IsDoubleClickToggleMaximizeProperty
static readonly DependencyProperty IsDoubleClickToggleMaximizeProperty
Definition
DreamineImage.cs:124
Dreamine.UI.Wpf.Controls.DreamineImage.ClickCommand
ICommand? ClickCommand
Definition
DreamineImage.cs:199
Dreamine.UI.Wpf.Controls.DreamineImage.IsDoubleClickToggleMaximize
bool IsDoubleClickToggleMaximize
Definition
DreamineImage.cs:241
Dreamine.UI.Wpf.Controls.DreamineImage.OnMouseMove
void OnMouseMove(object sender, MouseEventArgs e)
Definition
DreamineImage.cs:411
Dreamine.UI.Wpf.Controls.DreamineImage.Stretch
Stretch Stretch
Definition
DreamineImage.cs:255
Dreamine.UI.Wpf.Controls.DreamineImage._isDragging
bool _isDragging
Definition
DreamineImage.cs:327
Dreamine.UI.Wpf.Controls.DreamineImage.Source
ImageSource? Source
Definition
DreamineImage.cs:171
Dreamine.UI.Wpf.Controls.DreamineImage.FallbackSourceProperty
static readonly DependencyProperty FallbackSourceProperty
Definition
DreamineImage.cs:64
Dreamine.UI.Wpf.Controls.DreamineImage.CornerRadiusProperty
static readonly DependencyProperty CornerRadiusProperty
Definition
DreamineImage.cs:33
Dreamine.UI.Wpf.Controls.DreamineImage._pressPoint
Point _pressPoint
Definition
DreamineImage.cs:318
Dreamine.UI.Wpf.Controls.DreamineImage.OnPreviewMouseLeftButtonDown
void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
Definition
DreamineImage.cs:353
Dreamine.UI.Wpf.Controls.DreamineImage.IsWindowDragEnabledProperty
static readonly DependencyProperty IsWindowDragEnabledProperty
Definition
DreamineImage.cs:109
Dreamine.UI.Wpf.Controls.DreamineImage.SourceProperty
static readonly DependencyProperty SourceProperty
Definition
DreamineImage.cs:49
Dreamine.UI.Wpf.Controls.DreamineImage.CommandParameterProperty
static readonly DependencyProperty CommandParameterProperty
Definition
DreamineImage.cs:94
Dreamine.UI.Wpf.Controls.DreamineImage.CornerRadius
CornerRadius CornerRadius
Definition
DreamineImage.cs:156
Dreamine.UI.Wpf.Controls.DreamineImage.StretchProperty
static readonly DependencyProperty StretchProperty
Definition
DreamineImage.cs:140
Dreamine.UI.Wpf.Controls.DreamineImage.DreamineImage
static DreamineImage()
Definition
DreamineImage.cs:268
Controls
DreamineImage.cs
다음에 의해 생성됨 :
1.17.0