From ffa16604395fb4b4bc0b5f961f5357dfe33a98d3 Mon Sep 17 00:00:00 2001 From: Mahdi Hosseini Date: Fri, 11 Mar 2022 18:10:55 +0330 Subject: [PATCH] Update CoverView --- .../Controls/Cover/CoverView/CoverView.cs | 47 ++++--------------- .../HandyControls/Controls/CoverView.cs | 16 +++++++ 2 files changed, 25 insertions(+), 38 deletions(-) create mode 100644 src/Shared/HandyControl_Shared/HandyControls/Controls/CoverView.cs diff --git a/src/Shared/HandyControl_Shared/Controls/Cover/CoverView/CoverView.cs b/src/Shared/HandyControl_Shared/Controls/Cover/CoverView/CoverView.cs index 3fe0ed997..428261f7d 100644 --- a/src/Shared/HandyControl_Shared/Controls/Cover/CoverView/CoverView.cs +++ b/src/Shared/HandyControl_Shared/Controls/Cover/CoverView/CoverView.cs @@ -8,7 +8,7 @@ namespace HandyControl.Controls { - public class CoverView : RegularItemsControl + public partial class CoverView : RegularItemsControl { private readonly CoverViewContent _viewContent; @@ -35,11 +35,9 @@ private void CoverViewItem_OnSelected(object sender, RoutedEventArgs e) { if (e.OriginalSource is CoverViewItem item) { - item.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.TrueBox); - _selectedItem = item; - if (_viewContent != null) + if (_selectedItem == null) { - item.IsSelected = true; + item.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.TrueBox); _selectedItem = item; if (_viewContent != null) { @@ -53,8 +51,8 @@ private void CoverViewItem_OnSelected(object sender, RoutedEventArgs e) if (!Equals(_selectedItem, item)) { - _selectedItem.IsSelected = false; - item.IsSelected = true; + _selectedItem.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.FalseBox); + item.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.TrueBox); _selectedItem = item; if (_viewContent != null) { @@ -65,29 +63,15 @@ private void CoverViewItem_OnSelected(object sender, RoutedEventArgs e) return; } - if (!Equals(_selectedItem, item)) - { - _selectedItem.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.FalseBox); - item.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.TrueBox); - _selectedItem = item; if (_viewContent != null) { _viewContent.Content = null; _viewContent.ContentTemplate = null; UpdateCoverViewContent(false); } - _selectedItem.IsSelected = false; + _selectedItem.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.FalseBox); _selectedItem = null; } - - if (_viewContent != null) - { - _viewContent.Content = null; - _viewContent.ContentTemplate = null; - UpdateCoverViewContent(false); - } - _selectedItem.SetCurrentValue(SelectableItem.IsSelectedProperty, ValueBoxes.FalseBox); - _selectedItem = null; } } @@ -124,19 +108,6 @@ public Style CoverViewContentStyle set => SetValue(CoverViewContentStyleProperty, value); } - - - public bool ShowContent - { - get { return (bool)GetValue(ShowContentProperty); } - set { SetValue(ShowContentProperty, value); } - } - - public static readonly DependencyProperty ShowContentProperty = - DependencyProperty.Register("ShowContent", typeof(bool), typeof(CoverView), new PropertyMetadata(true)); - - - internal static readonly DependencyProperty GroupsProperty = DependencyProperty.Register( "Groups", typeof(int), typeof(CoverView), new FrameworkPropertyMetadata(ValueBoxes.Int5Box, FrameworkPropertyMetadataOptions.AffectsMeasure, @@ -215,7 +186,7 @@ protected override void Refresh() } /// - /// Update content view + /// 更新内容视图 /// private void UpdateCoverViewContent(bool isOpen) { @@ -242,7 +213,7 @@ private void UpdateCoverViewContent(bool isOpen) } /// - /// Update content view position + /// 更新内容视图位置 /// private void UpdateCoverViewContentPosition() { @@ -384,7 +355,7 @@ private void InsertItem(int index, object item) } /// - /// Generate index number + /// 生成序号 /// private void GenerateIndex() { diff --git a/src/Shared/HandyControl_Shared/HandyControls/Controls/CoverView.cs b/src/Shared/HandyControl_Shared/HandyControls/Controls/CoverView.cs new file mode 100644 index 000000000..acf29e922 --- /dev/null +++ b/src/Shared/HandyControl_Shared/HandyControls/Controls/CoverView.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace HandyControl.Controls +{ + public partial class CoverView + { + public bool ShowContent + { + get { return (bool) GetValue(ShowContentProperty); } + set { SetValue(ShowContentProperty, value); } + } + + public static readonly DependencyProperty ShowContentProperty = + DependencyProperty.Register("ShowContent", typeof(bool), typeof(CoverView), new PropertyMetadata(true)); + } +}