Dreamine.UI.Maui
1.0.1
Windows(WinUI)의 네이티브 `CheckBox`는 `WidthRequest`로 줄일 수 없는 거대한 최소 너비를 가져서 라벨과의 간격이 벌어지는 문제가 있어, 처음부터 직접 그려서 만들었습니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreamineCheckLed.xaml.cs
이 파일의 문서화 페이지로 가기
1
namespace
Dreamine.UI.Maui
;
2
11
public
enum
DreamineCheckLedCorner
12
{
21
TopLeft
,
30
TopRight
,
39
BottomLeft
,
48
BottomRight
49
}
50
59
public
partial class
DreamineCheckLed
: ContentView
60
{
69
public
static
readonly BindableProperty
IsOnProperty
= BindableProperty.Create(
70
nameof(
IsOn
), typeof(
bool
), typeof(
DreamineCheckLed
),
false
, propertyChanged:
OnVisualChanged
);
71
80
public
static
readonly BindableProperty
IsPulseProperty
= BindableProperty.Create(
81
nameof(
IsPulse
), typeof(
bool
), typeof(
DreamineCheckLed
),
false
, propertyChanged:
OnVisualChanged
);
82
91
public
static
readonly BindableProperty
DiameterProperty
= BindableProperty.Create(
92
nameof(
Diameter
), typeof(
double
), typeof(
DreamineCheckLed
), 24d, propertyChanged:
OnDiameterChanged
);
93
102
public
static
readonly BindableProperty
CornerProperty
= BindableProperty.Create(
103
nameof(
Corner
), typeof(
DreamineCheckLedCorner
), typeof(
DreamineCheckLed
),
DreamineCheckLedCorner
.TopLeft,
104
propertyChanged:
OnCornerChanged
);
105
114
public
bool
IsOn
115
{
116
get
=> (bool)GetValue(
IsOnProperty
);
117
set
=> SetValue(
IsOnProperty
, value);
118
}
119
128
public
bool
IsPulse
129
{
130
get
=> (bool)GetValue(
IsPulseProperty
);
131
set
=> SetValue(
IsPulseProperty
, value);
132
}
133
142
public
double
Diameter
143
{
144
get
=> (double)GetValue(
DiameterProperty
);
145
set
=> SetValue(
DiameterProperty
, value);
146
}
147
156
public
DreamineCheckLedCorner
Corner
157
{
158
get
=> (
DreamineCheckLedCorner
)GetValue(
CornerProperty
);
159
set
=> SetValue(
CornerProperty
, value);
160
}
161
170
public
DreamineCheckLed
()
171
{
172
InitializeComponent();
173
ApplyVisualState
();
174
ApplyCorner
();
175
176
// 생성자 시점엔 펄스를 건너뛰었으니, 실제로 화면에 붙어 Handler가 생기면 다시 적용한다.
177
HandlerChanged += (_, _) =>
ApplyVisualState
();
178
}
179
212
private
static
void
OnCornerChanged
(BindableObject bindable,
object
oldValue,
object
newValue)
213
{
214
if
(bindable is
DreamineCheckLed
led)
215
led.ApplyCorner();
216
}
217
226
private
void
ApplyCorner
()
227
{
228
HorizontalOptions =
Corner
is
DreamineCheckLedCorner.TopLeft
or
DreamineCheckLedCorner.BottomLeft
229
? LayoutOptions.Start
230
: LayoutOptions.End;
231
232
VerticalOptions =
Corner
is
DreamineCheckLedCorner.TopLeft
or
DreamineCheckLedCorner.TopRight
233
? LayoutOptions.Start
234
: LayoutOptions.End;
235
}
236
269
private
static
void
OnVisualChanged
(BindableObject bindable,
object
oldValue,
object
newValue)
270
{
271
if
(bindable is
DreamineCheckLed
led)
272
led.ApplyVisualState();
273
}
274
307
private
static
void
OnDiameterChanged
(BindableObject bindable,
object
oldValue,
object
newValue)
308
{
309
if
(bindable is
DreamineCheckLed
led)
310
{
311
led.Dot.WidthRequest = led.Diameter;
312
led.Dot.HeightRequest = led.Diameter;
313
led.Dot.StrokeShape =
new
Microsoft.Maui.Controls.Shapes.RoundRectangle { CornerRadius = led.Diameter / 2 };
314
}
315
}
316
325
private
void
ApplyVisualState
()
326
{
327
Dot.BackgroundColor =
IsOn
? Color.FromArgb(
"#1FD36B"
) : Color.FromArgb(
"#1A2A1A"
);
328
Dot.Stroke =
IsOn
? Color.FromArgb(
"#7DD9B7"
) : Color.FromArgb(
"#556677"
);
329
330
// Handler가 아직 없으면(= 화면에 붙기 전, 보통 생성자에서 호출되는 경우) IAnimationManager가
331
// 없어서 AbortAnimation/Animation.Commit이 ArgumentException을 던진다. 그 시점엔 애니메이션을
332
// 건너뛰고 단순히 최종 Opacity만 맞춰둔다 — 실제 애니메이션은 화면에 붙은 뒤 토글될 때 적용된다.
333
if
(Handler is
null
)
334
{
335
Dot.Opacity = 1.0;
336
return
;
337
}
338
339
this.AbortAnimation(
"PulseAnimation"
);
340
341
if
(
IsOn
&&
IsPulse
)
342
{
343
var animation =
new
Animation(v => Dot.Opacity = v, 1.0, 0.4);
344
animation.Commit(
this
,
"PulseAnimation"
, 16, 450, Easing.SinInOut, finished:
null
, repeat: () =>
IsOn
&&
IsPulse
);
345
}
346
else
347
{
348
Dot.Opacity = 1.0;
349
}
350
}
351
}
Dreamine.UI.Maui
Definition
DreamineCheckBox.xaml.cs:1
Dreamine.UI.Maui.DreamineCheckLedCorner
DreamineCheckLedCorner
Definition
DreamineCheckLed.xaml.cs:12
Dreamine.UI.Maui.DreamineCheckLedCorner.TopRight
@ TopRight
Definition
DreamineCheckLed.xaml.cs:30
Dreamine.UI.Maui.DreamineCheckLedCorner.BottomRight
@ BottomRight
Definition
DreamineCheckLed.xaml.cs:48
Dreamine.UI.Maui.DreamineCheckLedCorner.BottomLeft
@ BottomLeft
Definition
DreamineCheckLed.xaml.cs:39
Dreamine.UI.Maui.DreamineCheckLedCorner.TopLeft
@ TopLeft
Definition
DreamineCheckLed.xaml.cs:21
Dreamine.UI.Maui.DreamineCheckLed.DiameterProperty
static readonly BindableProperty DiameterProperty
Definition
DreamineCheckLed.xaml.cs:91
Dreamine.UI.Maui.DreamineCheckLed.Corner
DreamineCheckLedCorner Corner
Definition
DreamineCheckLed.xaml.cs:157
Dreamine.UI.Maui.DreamineCheckLed.IsPulse
bool IsPulse
Definition
DreamineCheckLed.xaml.cs:129
Dreamine.UI.Maui.DreamineCheckLed.CornerProperty
static readonly BindableProperty CornerProperty
Definition
DreamineCheckLed.xaml.cs:102
Dreamine.UI.Maui.DreamineCheckLed.OnDiameterChanged
static void OnDiameterChanged(BindableObject bindable, object oldValue, object newValue)
Definition
DreamineCheckLed.xaml.cs:307
Dreamine.UI.Maui.DreamineCheckLed.DreamineCheckLed
DreamineCheckLed()
Definition
DreamineCheckLed.xaml.cs:170
Dreamine.UI.Maui.DreamineCheckLed.Diameter
double Diameter
Definition
DreamineCheckLed.xaml.cs:143
Dreamine.UI.Maui.DreamineCheckLed.IsPulseProperty
static readonly BindableProperty IsPulseProperty
Definition
DreamineCheckLed.xaml.cs:80
Dreamine.UI.Maui.DreamineCheckLed.ApplyCorner
void ApplyCorner()
Definition
DreamineCheckLed.xaml.cs:226
Dreamine.UI.Maui.DreamineCheckLed.OnCornerChanged
static void OnCornerChanged(BindableObject bindable, object oldValue, object newValue)
Definition
DreamineCheckLed.xaml.cs:212
Dreamine.UI.Maui.DreamineCheckLed.IsOn
bool IsOn
Definition
DreamineCheckLed.xaml.cs:115
Dreamine.UI.Maui.DreamineCheckLed.ApplyVisualState
void ApplyVisualState()
Definition
DreamineCheckLed.xaml.cs:325
Dreamine.UI.Maui.DreamineCheckLed.OnVisualChanged
static void OnVisualChanged(BindableObject bindable, object oldValue, object newValue)
Definition
DreamineCheckLed.xaml.cs:269
Dreamine.UI.Maui.DreamineCheckLed.IsOnProperty
static readonly BindableProperty IsOnProperty
Definition
DreamineCheckLed.xaml.cs:69
DreamineCheckLed.xaml.cs
다음에 의해 생성됨 :
1.17.0