Dreamine.UI.Wpf
1.0.1
Dreamine.UI.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
AutoScrollListBoxBehavior.cs
이 파일의 문서화 페이지로 가기
1
using
System.Collections.Specialized;
2
using
System.Windows;
3
using
System.Windows.Controls;
4
5
namespace
Dreamine.UI.Wpf.Behaviors
;
6
23
public
static
class
AutoScrollListBoxBehavior
24
{
33
public
static
readonly DependencyProperty
IsEnabledProperty
=
34
DependencyProperty.RegisterAttached(
35
"IsEnabled"
,
36
typeof(
bool
),
37
typeof(
AutoScrollListBoxBehavior
),
38
new
PropertyMetadata(
false
,
OnIsEnabledChanged
));
39
72
public
static
void
SetIsEnabled
(DependencyObject element,
bool
value)
73
=> element.SetValue(
IsEnabledProperty
, value);
74
107
public
static
bool
GetIsEnabled
(DependencyObject element)
108
=> (bool)element.GetValue(
IsEnabledProperty
);
109
118
private
static
readonly DependencyProperty
SubscriptionProperty
=
119
DependencyProperty.RegisterAttached(
120
"Subscription"
,
121
typeof(NotifyCollectionChangedEventHandler),
122
typeof(
AutoScrollListBoxBehavior
),
123
new
PropertyMetadata(
null
));
124
149
private
static
void
OnIsEnabledChanged
(DependencyObject d, DependencyPropertyChangedEventArgs e)
150
{
151
if
(d is not ListBox listBox)
152
return
;
153
154
if
((
bool
)e.NewValue)
155
{
156
listBox.Loaded +=
OnLoaded
;
157
listBox.Unloaded +=
OnUnloaded
;
158
}
159
else
160
{
161
listBox.Loaded -=
OnLoaded
;
162
listBox.Unloaded -=
OnUnloaded
;
163
Detach
(listBox);
164
}
165
}
166
191
private
static
void
OnLoaded
(
object
sender, RoutedEventArgs e)
192
{
193
if
(sender is not ListBox listBox)
194
return
;
195
196
Attach
(listBox);
197
ScrollToLast
(listBox);
198
}
199
224
private
static
void
OnUnloaded
(
object
sender, RoutedEventArgs e)
225
{
226
if
(sender is not ListBox listBox)
227
return
;
228
229
Detach
(listBox);
230
}
231
248
private
static
void
Attach
(ListBox listBox)
249
{
250
Detach
(listBox);
251
252
if
(listBox.ItemsSource is not INotifyCollectionChanged incc)
253
return
;
254
255
NotifyCollectionChangedEventHandler handler = (_, __) =>
256
{
257
listBox.Dispatcher.InvokeAsync(() =>
ScrollToLast
(listBox));
258
};
259
260
incc.CollectionChanged += handler;
261
listBox.SetValue(
SubscriptionProperty
, handler);
262
}
263
280
private
static
void
Detach
(ListBox listBox)
281
{
282
if
(listBox.ItemsSource is INotifyCollectionChanged incc &&
283
listBox.GetValue(
SubscriptionProperty
) is NotifyCollectionChangedEventHandler handler)
284
{
285
incc.CollectionChanged -= handler;
286
}
287
288
listBox.ClearValue(
SubscriptionProperty
);
289
}
290
307
private
static
void
ScrollToLast
(ListBox listBox)
308
{
309
if
(listBox.Items.Count <= 0)
310
return
;
311
312
var last = listBox.Items[listBox.Items.Count - 1];
313
listBox.ScrollIntoView(last);
314
}
315
}
Dreamine.UI.Wpf.Behaviors
Definition
AutoScrollListBoxBehavior.cs:5
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior
Definition
AutoScrollListBoxBehavior.cs:24
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.OnLoaded
static void OnLoaded(object sender, RoutedEventArgs e)
Definition
AutoScrollListBoxBehavior.cs:191
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.ScrollToLast
static void ScrollToLast(ListBox listBox)
Definition
AutoScrollListBoxBehavior.cs:307
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.GetIsEnabled
static bool GetIsEnabled(DependencyObject element)
Definition
AutoScrollListBoxBehavior.cs:107
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.OnIsEnabledChanged
static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Definition
AutoScrollListBoxBehavior.cs:149
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.Attach
static void Attach(ListBox listBox)
Definition
AutoScrollListBoxBehavior.cs:248
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.SetIsEnabled
static void SetIsEnabled(DependencyObject element, bool value)
Definition
AutoScrollListBoxBehavior.cs:72
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.SubscriptionProperty
static readonly DependencyProperty SubscriptionProperty
Definition
AutoScrollListBoxBehavior.cs:118
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.OnUnloaded
static void OnUnloaded(object sender, RoutedEventArgs e)
Definition
AutoScrollListBoxBehavior.cs:224
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.Detach
static void Detach(ListBox listBox)
Definition
AutoScrollListBoxBehavior.cs:280
Dreamine.UI.Wpf.Behaviors.AutoScrollListBoxBehavior.IsEnabledProperty
static readonly DependencyProperty IsEnabledProperty
Definition
AutoScrollListBoxBehavior.cs:33
Behaviors
AutoScrollListBoxBehavior.cs
다음에 의해 생성됨 :
1.17.0