Skip to content

Commit

Permalink
feat: support ToggleButtonGroup option IsCanCancel
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Sep 10, 2024
1 parent fcf8936 commit 343d1c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Test/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
<StackPanel Margin="0,8,0,0" Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<vio:ToggleButtonGroup x:Key="ToggleButtonGroup" />
<vio:ToggleButtonGroup x:Key="ToggleButtonGroup" IsCanCancel="True" />
</StackPanel.Resources>
<ToggleButton
vio:ToggleButtonGroup.Group="{DynamicResource ToggleButtonGroup}"
Expand Down
7 changes: 5 additions & 2 deletions src/Wpf.Ui.Violeta/Controls/Primitives/ToggleButtonGroup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace Wpf.Ui.Violeta.Controls.Primitives;

public class ToggleButtonGroup : List<ToggleButton>
{
public bool IsCanCancel { get; set; } = false;

public static ToggleButtonGroup GetGroup(DependencyObject obj)
{
return (ToggleButtonGroup)obj.GetValue(GroupProperty);
Expand Down Expand Up @@ -56,9 +59,9 @@ public void Join(ToggleButton toggleButton)
};
toggleButton.Unchecked += (s, e) =>
{
if (!Handling && s is ToggleButton tb)
if (!IsCanCancel && !Handling && s is ToggleButton cb)
{
tb.IsChecked = true;
cb.IsChecked = true;
}
};
SetGroup(toggleButton, this);
Expand Down

0 comments on commit 343d1c6

Please sign in to comment.