整理控件库
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,17 +121,17 @@
|
||||
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
|
||||
<!-- Universal WPF UI ContextMenu -->
|
||||
<Setter Property="Background" Value="{DynamicResource ComboBoxBackground}" />
|
||||
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
|
||||
<Setter Property="Border.CornerRadius" Value="{StaticResource ControlCornerRadius}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="{StaticResource ComboBoxBorderThemeThickness}" />
|
||||
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
|
||||
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForeground}" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
|
||||
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
|
||||
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
|
||||
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="Padding" Value="{DynamicResource ComboBoxPadding}" />
|
||||
<Setter Property="Padding" Value="{StaticResource ComboBoxPadding}" />
|
||||
<Setter Property="Popup.Placement" Value="Bottom" />
|
||||
<Setter Property="Popup.PopupAnimation" Value="Slide" />
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
|
||||
@@ -146,6 +146,7 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:CheckComboBox}">
|
||||
<DockPanel>
|
||||
<!-- 标题 -->
|
||||
<TextBlock
|
||||
x:Name="Header_TextBlock"
|
||||
Margin="5"
|
||||
@@ -160,8 +161,6 @@
|
||||
<!-- 强调边缘 只有IsEditable时出现 -->
|
||||
<Border
|
||||
x:Name="AccentBorder"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
BorderBrush="{DynamicResource ComboBoxBorderBrushFocused}"
|
||||
BorderThickness="{StaticResource ComboBoxAccentBorderThemeThickness}"
|
||||
CornerRadius="{TemplateBinding Border.CornerRadius}"
|
||||
@@ -172,8 +171,6 @@
|
||||
MinWidth="{TemplateBinding MinWidth}"
|
||||
MinHeight="{TemplateBinding MinHeight}"
|
||||
Padding="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
|
||||
Reference in New Issue
Block a user