Skip to content

Commit

Permalink
1.2.2.1 (#223)
Browse files Browse the repository at this point in the history
* 1.2.2.1
  • Loading branch information
Mochengvia authored Jul 8, 2024
1 parent 41e2ae7 commit af685d6
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Implements\NoticeHandlerImpl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implements\PendingHandlerImpl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ClassNameInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\EnumInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\MessageBoxContent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Resources\Converters.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Resources\StyleKeys.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsChecked, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="True" />
<Condition Binding="{Binding Path=(local:ExpanderHelper.ExpandedHeaderForeground), Converter={x:Static pw:Converters.IsNonnullConverter}, RelativeSource={RelativeSource AncestorType=Expander}, Mode=OneWay}"
<Condition Binding="{Binding Path=(local:ExpanderHelper.ExpandedHeaderCornerRadius), Converter={x:Static pw:Converters.IsNonnullConverter}, RelativeSource={RelativeSource AncestorType=Expander}, Mode=OneWay}"
Value="True" />
</MultiDataTrigger.Conditions>
<Setter TargetName="BdrContainer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ClearButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
</MultiDataTrigger.Conditions>
<Setter TargetName="BtnClear"
Expand All @@ -197,7 +197,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ClearButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnHoverAndNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="True" />
Expand All @@ -221,7 +221,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ClearButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnFocusedAndNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
<Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="True" />
Expand All @@ -240,7 +240,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding UpDownButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
</MultiDataTrigger.Conditions>
<Setter TargetName="GrdUpDown"
Expand All @@ -262,7 +262,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding UpDownButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnHoverAndNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="True" />
Expand All @@ -286,7 +286,7 @@
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding UpDownButtonVisibility, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="VisibleOnFocusedAndNonnull" />
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, RelativeSource={RelativeSource Self}, Mode=OneWay}"
<Condition Binding="{Binding Text, Converter={x:Static pw:Converters.IsStringNonnullAndNotEmptyConverter}, ElementName=PART_InputTextBox, Mode=OneWay}"
Value="True" />
<Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}, Mode=OneWay}"
Value="True" />
Expand Down
45 changes: 45 additions & 0 deletions SourceCode/SharedResources/Panuon.WPF.UI/Controls/MultiComboBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Panuon.WPF.UI.Internal;
using Panuon.WPF.UI.Internal.Models;
using Panuon.WPF.UI.Internal.Utils;
using System;
using System.Collections;
Expand Down Expand Up @@ -78,6 +79,17 @@ public event RoutedEventHandler ItemRemoved

#region Properties

#region BindToEnum
public Enum BindToEnum
{
get { return (Enum)GetValue(BindToEnumProperty); }
set { SetValue(BindToEnumProperty, value); }
}

public static readonly DependencyProperty BindToEnumProperty =
DependencyProperty.Register("BindToEnum", typeof(Enum), typeof(MultiComboBox), new PropertyMetadata(OnBindToEnumChanged));
#endregion

#region ClearCommand
public ICommand ClearCommand
{
Expand Down Expand Up @@ -837,6 +849,39 @@ private void DropDown_Closed(object sender, EventArgs e)
}
#endregion

#region Event Handlers
private static void OnBindToEnumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var comboBox = d as MultiComboBox;

var type = e.NewValue?.GetType();

if (type != null)
{
var enumList = new List<EnumInfo>();
foreach (Enum item in Enum.GetValues(type))
{
var field = type.GetField(item.ToString());
if (null != field)
{
var descriptions = field.GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
if (descriptions.Length > 0)
{
enumList.Add(new EnumInfo(descriptions[0].Description, item));
}
else
{
enumList.Add(new EnumInfo(item.ToString(), item));
}
}
}
comboBox.DisplayMemberPath = nameof(EnumInfo.DisplayName);
comboBox.SelectedValuePath = nameof(EnumInfo.Value);
comboBox.ItemsSource = enumList;
}
}
#endregion

#region Functions
private static void OnRemoveCommandExecute(object obj)
{
Expand Down
37 changes: 19 additions & 18 deletions SourceCode/SharedResources/Panuon.WPF.UI/Controls/NumberInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,29 +582,30 @@ private void UpdateTextFromValue()
{
return;
}
if (_isInternalSet)
{
return;
}

_isInternalSet = true;

_inputTextBox.Text = Value == null
? null
: FormatValueText();

_isInternalSet = false;
try
{
_isInternalSet = true;

var carentIndex = _inputTextBox.CaretIndex;
_inputTextBox.Text = Value == null
? null
: FormatValueText();
if (carentIndex != -1)
{
_inputTextBox.Select(carentIndex, 0);
}
}
finally
{
_isInternalSet = false;
}
}

private void UpdateValueFromText()
{
if (_inputTextBox == null)
{
return;
}

if (_isInternalSet)
if (_isInternalSet
|| _inputTextBox == null)
{
return;
}
Expand All @@ -627,7 +628,7 @@ private void UpdateValueFromText()
else if (double.TryParse(_inputTextBox.Text, out double doubleValue))
{
SetCurrentValue(ValueProperty, doubleValue);
if(Value != doubleValue)
if (Value != doubleValue)
{
UpdateTextFromValue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
using System.Windows;
using Panuon.WPF.UI.Internal.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

Expand All @@ -7,10 +14,17 @@ namespace Panuon.WPF.UI
public class ToggleButtonGroup
: MultiSelector
{
#region Fields
private string _groupId = Guid.NewGuid().ToString();
#endregion

#region Ctor
static ToggleButtonGroup()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ToggleButtonGroup), new FrameworkPropertyMetadata(typeof(ToggleButtonGroup)));
DefaultStyleKeyProperty.OverrideMetadata(
typeof(ToggleButtonGroup),
new FrameworkPropertyMetadata(typeof(ToggleButtonGroup))
);
}

public ToggleButtonGroup()
Expand All @@ -23,12 +37,19 @@ public ToggleButtonGroup()
#region Overrides
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is ToggleButton;
if (item is ToggleButton toggleButton)
{
ToggleButtonHelper.SetGroupName(toggleButton, AllowMultipleSelection ? null : _groupId);
return true;
}
return false;
}

protected override DependencyObject GetContainerForItemOverride()
{
return new ToggleButton();
var toggleButton = new ToggleButton();
ToggleButtonHelper.SetGroupName(toggleButton, AllowMultipleSelection ? null : _groupId);
return toggleButton;
}
#endregion

Expand All @@ -39,6 +60,28 @@ protected override DependencyObject GetContainerForItemOverride()

#region Properties

#region AllowMultipleSelection
public bool AllowMultipleSelection
{
get { return (bool)GetValue(AllowMultipleSelectionProperty); }
set { SetValue(AllowMultipleSelectionProperty, value); }
}

public static readonly DependencyProperty AllowMultipleSelectionProperty =
DependencyProperty.Register("AllowMultipleSelection", typeof(bool), typeof(ToggleButtonGroup), new PropertyMetadata(true, OnAllowMultipleSelectionChanged));
#endregion

#region BindToEnum
public Enum BindToEnum
{
get { return (Enum)GetValue(BindToEnumProperty); }
set { SetValue(BindToEnumProperty, value); }
}

public static readonly DependencyProperty BindToEnumProperty =
DependencyProperty.Register("BindToEnum", typeof(Enum), typeof(ToggleButtonGroup), new PropertyMetadata(OnBindToEnumChanged));
#endregion

#region ItemsWidth
public double ItemsWidth
{
Expand Down Expand Up @@ -306,7 +349,42 @@ public VerticalAlignment ItemsVerticalContentAlignment
#endregion

#region Event Handlers
private static void OnBindToEnumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var toggleButtonGroup = d as ToggleButtonGroup;

var type = e.NewValue?.GetType();

if (type != null)
{
var enumList = new List<EnumInfo>();
foreach (Enum item in Enum.GetValues(type))
{
var field = type.GetField(item.ToString());
if (null != field)
{
var descriptions = field.GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
if (descriptions.Length > 0)
{
enumList.Add(new EnumInfo(descriptions[0].Description, item));
}
else
{
enumList.Add(new EnumInfo(item.ToString(), item));
}
}
}
toggleButtonGroup.DisplayMemberPath = nameof(EnumInfo.DisplayName);
toggleButtonGroup.SelectedValuePath = nameof(EnumInfo.Value);
toggleButtonGroup.ItemsSource = enumList;
}
}

private static void OnAllowMultipleSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var toggleButtonGroup = d as ToggleButtonGroup;
toggleButtonGroup.OnAllowMultipleSelectionChanged();
}

private void OnToggleButtonCheckChanged(object sender, RoutedEventArgs e)
{
Expand All @@ -325,5 +403,15 @@ private void OnToggleButtonCheckChanged(object sender, RoutedEventArgs e)
}
}
#endregion

#region Functions
private void OnAllowMultipleSelectionChanged()
{
foreach (ToggleButton toggleButton in ItemContainerGenerator.Items)
{
ToggleButtonHelper.SetGroupName(toggleButton, AllowMultipleSelection ? null : _groupId);
}
}
#endregion
}
}
20 changes: 7 additions & 13 deletions SourceCode/SharedResources/Panuon.WPF.UI/Helpers/ComboBoxHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Panuon.WPF.UI.Internal;
using Panuon.WPF.UI.Internal.Models;
using Panuon.WPF.UI.Internal.Utils;
using System;
using System.Collections;
Expand Down Expand Up @@ -1233,24 +1234,17 @@ private static void OnBindToEnumChanged(DependencyObject d, DependencyPropertyCh
var descriptions = field.GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
if (descriptions.Length > 0)
{
enumList.Add(new
{
Name = descriptions[0].Description,
Enum = item,
});
enumList.Add(new EnumInfo(descriptions[0].Description, item));
}
else
enumList.Add(new
{
Name = item.ToString(),
Enum = item,
});
{
enumList.Add(new EnumInfo(item.ToString(), item));
}
}
}
comboBox.DisplayMemberPath = nameof(EnumInfo.DisplayName);
comboBox.SelectedValuePath = nameof(EnumInfo.Value);
comboBox.ItemsSource = enumList;
comboBox.DisplayMemberPath = "Name";
comboBox.SelectedValuePath = "Enum";
comboBox.SetCurrentValue(ComboBox.SelectedValueProperty, comboBox.SelectedValue ?? e.NewValue);
}
}

Expand Down
Loading

0 comments on commit af685d6

Please sign in to comment.