整理控件库

This commit is contained in:
GG Z
2025-05-05 17:04:06 +08:00
parent 74532b77be
commit 3eaad7566e
283 changed files with 2156 additions and 17846 deletions

View File

@@ -1,15 +1,16 @@
using WPFluent.Extensions;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using WPFluent.Extensions;
namespace WPFluent.Controls
{
@@ -28,24 +29,24 @@ namespace WPFluent.Controls
var itemContent = Convert.ToString(item.Content);
SelectedStrList ??= [];
SelectedObjList ??= [];
if(item.IsSelected)
if (item.IsSelected)
{
if(!SelectedStrList.Contains(item.Content))
if (!SelectedStrList.Contains(item.Content))
{
SelectedStrList.Add(itemContent);
}
if(!SelectedObjList.Contains(item.DataContext))
if (!SelectedObjList.Contains(item.DataContext))
{
SelectedObjList.Add(item.DataContext);
}
}
else
{
if(SelectedStrList.Contains(itemContent))
if (SelectedStrList.Contains(itemContent))
{
SelectedStrList.Remove(itemContent);
}
if(SelectedObjList.Contains(item.DataContext))
if (SelectedObjList.Contains(item.DataContext))
{
SelectedObjList.Remove(item.DataContext);
}
@@ -56,7 +57,7 @@ namespace WPFluent.Controls
#region PrivateProperty
private ContentPresenter PART_ContentSite;
private TextBox PART_FilterTextBox;
private System.Windows.Controls.TextBox PART_FilterTextBox;
private ICollectionView view;
private Popup PART_Popup;
@@ -110,7 +111,7 @@ namespace WPFluent.Controls
private static void OnSelectedObjListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var checkComboBox = d as CheckComboBox;
if(checkComboBox.ItemsSource != null)
if (checkComboBox.ItemsSource != null)
checkComboBox.SetCheckComboBoxValueAndContent();
}
#endregion
@@ -167,24 +168,24 @@ namespace WPFluent.Controls
{
base.OnApplyTemplate();
if(PART_FilterTextBox != null)
if (PART_FilterTextBox != null)
{
PART_FilterTextBox.TextChanged -= PART_FilterTextBox_TextChanged;
}
if(PART_Popup != null)
if (PART_Popup != null)
{
PART_Popup.Opened -= PART_Popup_Opened;
}
PART_ContentSite = GetTemplateChild("PART_ContentSite") as ContentPresenter;
PART_FilterTextBox = GetTemplateChild("PART_FilterTextBox") as TextBox;
PART_FilterTextBox = GetTemplateChild("PART_FilterTextBox") as System.Windows.Controls.TextBox;
PART_Popup = GetTemplateChild("PART_Popup") as Popup;
if(PART_FilterTextBox != null)
if (PART_FilterTextBox != null)
{
PART_FilterTextBox.TextChanged += PART_FilterTextBox_TextChanged;
}
view = CollectionViewSource.GetDefaultView(ItemsSource);
if(PART_Popup != null)
if (PART_Popup != null)
{
PART_Popup.Opened += PART_Popup_Opened;
}
@@ -193,9 +194,9 @@ namespace WPFluent.Controls
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
if(item is not CheckComboBoxItem)
if (item is not CheckComboBoxItem)
{
if(element is CheckComboBoxItem checkComboBoxItem && !string.IsNullOrEmpty(DisplayMemberPath))
if (element is CheckComboBoxItem checkComboBoxItem && !string.IsNullOrEmpty(DisplayMemberPath))
{
var binding = new Binding(DisplayMemberPath);
checkComboBoxItem.SetBinding(CheckComboBoxItem.ContentProperty, binding);
@@ -218,11 +219,11 @@ namespace WPFluent.Controls
{
popupIsFirstOpen = true;
if(SelectedObjList != null)
if (SelectedObjList != null)
{
foreach(var obj in SelectedObjList)
foreach (var obj in SelectedObjList)
{
if(string.IsNullOrWhiteSpace(DisplayMemberPath))
if (string.IsNullOrWhiteSpace(DisplayMemberPath))
{
SelectedStrList.Add(obj.ToString());
}
@@ -237,10 +238,10 @@ namespace WPFluent.Controls
private void SetCheckComboBoxValueAndContent()
{
if(SelectedObjList == null || SelectedObjList.Count <= 0)
if (SelectedObjList == null || SelectedObjList.Count <= 0)
SelectedStrList = [];
if(SelectedStrList == null)
if (SelectedStrList == null)
return;
Content = SelectedStrList.Count > MaxShowNumber
@@ -260,17 +261,17 @@ namespace WPFluent.Controls
/// </summary>
private void PART_Popup_Opened(object sender, EventArgs e)
{
if(!popupIsFirstOpen)
if (!popupIsFirstOpen)
return;
popupIsFirstOpen = false;
if(ItemsSource == null || SelectedObjList == null)
if (ItemsSource == null || SelectedObjList == null)
return;
foreach(var obj in SelectedObjList)
foreach (var obj in SelectedObjList)
{
if(ItemContainerGenerator.ContainerFromItem(obj) is CheckComboBoxItem checkComboBoxItem)
if (ItemContainerGenerator.ContainerFromItem(obj) is CheckComboBoxItem checkComboBoxItem)
checkComboBoxItem.IsSelected = true;
}
}
@@ -280,7 +281,7 @@ namespace WPFluent.Controls
/// </summary>
private void PART_FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if(PART_FilterTextBox == null || view == null)
if (PART_FilterTextBox == null || view == null)
return;
view.Filter += (o) =>
@@ -288,9 +289,9 @@ namespace WPFluent.Controls
var value = Convert.ToString(o.GetPropertyValue(DisplayMemberPath)).ToLower();
return value.Contains(PART_FilterTextBox.Text);
};
foreach(var obj in SelectedObjList)
foreach (var obj in SelectedObjList)
{
if(ItemContainerGenerator.ContainerFromItem(obj) is CheckComboBoxItem checkComboBoxItem)
if (ItemContainerGenerator.ContainerFromItem(obj) is CheckComboBoxItem checkComboBoxItem)
checkComboBoxItem.IsSelected = true;
}
}