Synchronize the Net40

This commit is contained in:
NaBian committed 2019-01-31 21:10:51 +08:00
1 parent b3c3173c46
commit ab6e2efe21
87 files changed
+2743 -349

No files matched your search

@@ -29,11 +29,38 @@ namespace HandyControl.Controls
if (_isMouseLeftButtonDown)
{
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
if (SelfManage)
{
if (!IsSelected)
{
IsSelected = true;
OnSelected(new RoutedEventArgs(SelectedEvent, this));
}
else if (CanDeselect)
{
IsSelected = false;
OnSelected(new RoutedEventArgs(DeselectedEvent, this));
}
}
else
{
if (CanDeselect)
{
OnSelected(IsSelected
? new RoutedEventArgs(DeselectedEvent, this)
: new RoutedEventArgs(SelectedEvent, this));
}
else
{
OnSelected(new RoutedEventArgs(SelectedEvent, this));
}
}
_isMouseLeftButtonDown = false;
}
}
protected virtual void OnSelected(RoutedEventArgs e) => RaiseEvent(e);
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
@@ -43,6 +70,24 @@ namespace HandyControl.Controls
set => SetValue(IsSelectedProperty, value);
}
public static readonly DependencyProperty SelfManageProperty = DependencyProperty.Register(
"SelfManage", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
public bool SelfManage
{
get => (bool)GetValue(SelfManageProperty);
set => SetValue(SelfManageProperty, value);
}
public static readonly DependencyProperty CanDeselectProperty = DependencyProperty.Register(
"CanDeselect", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
public bool CanDeselect
{
get => (bool)GetValue(CanDeselectProperty);
set => SetValue(CanDeselectProperty, value);
}
public static readonly RoutedEvent SelectedEvent =
EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(SelectableItem));
@@ -52,5 +97,15 @@ namespace HandyControl.Controls
add => AddHandler(SelectedEvent, value);
remove => RemoveHandler(SelectedEvent, value);
}
public static readonly RoutedEvent DeselectedEvent =
EventManager.RegisterRoutedEvent("Deselected", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(SelectableItem));
public event RoutedEventHandler Deselected
{
add => AddHandler(DeselectedEvent, value);
remove => RemoveHandler(DeselectedEvent, value);
}
}
}
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows;
@@ -25,25 +26,35 @@ namespace HandyControl.Controls
"ItemContainerStyle", typeof(Style), typeof(SimpleItemsControl),
new PropertyMetadata(default(Style), OnItemContainerStyleChanged));
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
"ItemsSource", typeof(IEnumerable), typeof(SimpleItemsControl),
new PropertyMetadata(default(IEnumerable), OnItemsSourceChanged));
public SimpleItemsControl()
{
var items = new ObservableCollection<object>();
items.CollectionChanged += OnItemsCollectionChanged;
items.CollectionChanged += OnItemsChanged;
Items = items;
}
public IEnumerable ItemsSource
{
get => (IEnumerable)GetValue(ItemsSourceProperty);
set => SetValue(ItemsSourceProperty, value);
}
[Bindable(true)]
[Category("Content")]
public Style ItemContainerStyle
{
get => (Style) GetValue(ItemContainerStyleProperty);
get => (Style)GetValue(ItemContainerStyleProperty);
set => SetValue(ItemContainerStyleProperty, value);
}
[Bindable(true)]
public DataTemplate ItemTemplate
{
get => (DataTemplate) GetValue(ItemTemplateProperty);
get => (DataTemplate)GetValue(ItemTemplateProperty);
set => SetValue(ItemTemplateProperty, value);
}
@@ -53,6 +64,15 @@ namespace HandyControl.Controls
internal Panel ItemsHost { get; set; }
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((SimpleItemsControl)d).OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
}
protected virtual void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
{
}
public override void OnApplyTemplate()
{
ItemsHost?.Children.Clear();
@@ -63,7 +83,7 @@ namespace HandyControl.Controls
Refresh();
}
private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
protected virtual void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Refresh();
UpdateItems();
@@ -89,16 +109,14 @@ namespace HandyControl.Controls
}
private static void OnItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var target = d as SimpleItemsControl;
target?.Refresh();
}
=> (d as SimpleItemsControl)?.OnItemTemplateChanged(e);
protected virtual void OnItemTemplateChanged(DependencyPropertyChangedEventArgs e) => Refresh();
private static void OnItemContainerStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var target = d as SimpleItemsControl;
target?.Refresh();
}
=> (d as SimpleItemsControl)?.OnItemContainerStyleChanged(e);
protected virtual void OnItemContainerStyleChanged(DependencyPropertyChangedEventArgs e) => Refresh();
protected virtual void Refresh()
{
@@ -128,7 +146,6 @@ namespace HandyControl.Controls
protected virtual void UpdateItems()
{
}
}
}