Skip to content

Commit

Permalink
fix: #1188 #1014 #981 #569 #1119
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Sep 3, 2022
1 parent a035c8c commit 7519c7e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
</Style>

<Style x:Key="CheckComboBoxItemBaseStyle" TargetType="hc:CheckComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Padding" Value="{StaticResource DefaultControlPadding}"/>
<Setter Property="Background" Value="Transparent"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7435,6 +7435,8 @@
</Setter>
</Style>
<Style x:Key="CheckComboBoxItemBaseStyle" TargetType="hc:CheckComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Padding" Value="{StaticResource DefaultControlPadding}" />
<Setter Property="Background" Value="Transparent" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
Expand Down Expand Up @@ -124,16 +123,6 @@ public CheckComboBox()
SetCurrentValue(SelectedIndexProperty, -1);
SelectedItems.Clear();
}));

ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
}

private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
if (ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
{
UpdateTags();
}
}

public override void OnApplyTemplate()
Expand All @@ -151,14 +140,10 @@ public override void OnApplyTemplate()
if (_selectAllItem != null)
{
_selectAllItem.Selected += SelectAllItem_Selected;
_selectAllItem.Unselected += SelectAllItem_Unselected;
_selectAllItem.Unselected += SelectAllItem_Unselected;
}

Dispatcher.BeginInvoke(new Action(() =>
{
IsDropDownOpen = true;
IsDropDownOpen = false;
}), DispatcherPriority.DataBind);
UpdateTags();
}

public bool VerifyData()
Expand Down Expand Up @@ -226,9 +211,10 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e)

private void Tags_OnClosed(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is Tag { Tag: CheckComboBoxItem checkComboBoxItem })
if (e.OriginalSource is Tag tag)
{
checkComboBoxItem.SetCurrentValue(IsSelectedProperty, false);
SelectedItems.Remove(tag.Tag);
_panel.Children.Remove(tag);
}
}

Expand All @@ -237,12 +223,13 @@ private void SwitchAllItems(bool selected)
if (_isInternalAction) return;
_isInternalAction = true;

foreach (var item in Items)
if (!selected)
{
if (ItemContainerGenerator.ContainerFromItem(item) is CheckComboBoxItem checkComboBoxItem)
{
checkComboBoxItem.SetCurrentValue(ListBoxItem.IsSelectedProperty, selected);
}
UnselectAll();
}
else
{
SelectAll();
}

_isInternalAction = false;
Expand All @@ -268,25 +255,22 @@ private void UpdateTags()

foreach (var item in SelectedItems)
{
if (ItemContainerGenerator.ContainerFromItem(item) is CheckComboBoxItem checkComboBoxItem)
var tag = new Tag
{
Style = TagStyle,
Tag = item
};

if (ItemsSource != null)
{
var tag = new Tag
{
Style = TagStyle,
Tag = checkComboBoxItem
};

if (ItemsSource != null)
{
tag.SetBinding(ContentControl.ContentProperty, new Binding(DisplayMemberPath) { Source = item });
}
else
{
tag.Content = checkComboBoxItem.Content;
}

_panel.Children.Add(tag);
tag.SetBinding(ContentControl.ContentProperty, new Binding(DisplayMemberPath) { Source = item });
}
else
{
tag.Content = IsItemItsOwnContainerOverride(item) ? ((CheckComboBoxItem) item).Content : item;
}

_panel.Children.Add(tag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
</Style>

<Style x:Key="CheckComboBoxItemBaseStyle" TargetType="hc:CheckComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Padding" Value="{StaticResource DefaultControlPadding}"/>
<Setter Property="Background" Value="Transparent"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Shared/HandyControl_Shared/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7517,6 +7517,8 @@
</Setter>
</Style>
<Style x:Key="CheckComboBoxItemBaseStyle" TargetType="hc:CheckComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Padding" Value="{StaticResource DefaultControlPadding}" />
<Setter Property="Background" Value="Transparent" />
Expand Down

0 comments on commit 7519c7e

Please sign in to comment.