diff --git a/demo/Ursa.Demo/Pages/ButtonGroupDemo.axaml b/demo/Ursa.Demo/Pages/ButtonGroupDemo.axaml
index 30c0a03..3026968 100644
--- a/demo/Ursa.Demo/Pages/ButtonGroupDemo.axaml
+++ b/demo/Ursa.Demo/Pages/ButtonGroupDemo.axaml
@@ -13,10 +13,20 @@
mc:Ignorable="d">
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/Ursa.Demo/ViewModels/ButtonGroupDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/ButtonGroupDemoViewModel.cs
index 88c5299..02f6ea1 100644
--- a/demo/Ursa.Demo/ViewModels/ButtonGroupDemoViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/ButtonGroupDemoViewModel.cs
@@ -1,11 +1,35 @@
using System.Collections.ObjectModel;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using CommunityToolkit.Mvvm.Input;
+using Ursa.Controls;
namespace Ursa.Demo.ViewModels;
public class ButtonGroupDemoViewModel: ViewModelBase
{
- public ObservableCollection Items { get; set; } = new ()
+ public ObservableCollection Items { get; set; } = new ()
{
- "Ding", "Otter", "Husky", "Mr. 17", "Cass"
+ new ButtonItem(){Name = "Ding" },
+ new ButtonItem(){Name = "Otter" },
+ new ButtonItem(){Name = "Husky" },
+ new ButtonItem(){Name = "Mr. 17" },
+ new ButtonItem(){Name = "Cass" },
};
+}
+
+public class ButtonItem
+{
+ public string? Name { get; set; }
+ public ICommand InvokeCommand { get; set; }
+
+ public ButtonItem()
+ {
+ InvokeCommand = new AsyncRelayCommand(Invoke);
+ }
+
+ private async Task Invoke()
+ {
+ await MessageBox.ShowAsync("Hello " + Name);
+ }
}
\ No newline at end of file
diff --git a/src/Ursa.Themes.Semi/Controls/ButtonGroup.axaml b/src/Ursa.Themes.Semi/Controls/ButtonGroup.axaml
index 15a70c1..06136d4 100644
--- a/src/Ursa.Themes.Semi/Controls/ButtonGroup.axaml
+++ b/src/Ursa.Themes.Semi/Controls/ButtonGroup.axaml
@@ -63,6 +63,7 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
+ ContentTemplate="{TemplateBinding ContentTemplate}"
FontWeight="{TemplateBinding FontWeight}"
Foreground="{TemplateBinding Foreground}" />
diff --git a/src/Ursa/Controls/ButtonGroup.cs b/src/Ursa/Controls/ButtonGroup.cs
index 773a1b4..92f997c 100644
--- a/src/Ursa/Controls/ButtonGroup.cs
+++ b/src/Ursa/Controls/ButtonGroup.cs
@@ -3,6 +3,7 @@ using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
+using Avalonia.Data;
using Avalonia.Media;
using Avalonia.Metadata;
@@ -10,6 +11,40 @@ namespace Ursa.Controls;
public class ButtonGroup: ItemsControl
{
+ public static readonly StyledProperty CommandBindingProperty = AvaloniaProperty.Register(
+ nameof(CommandBinding));
+
+ [AssignBinding]
+ [InheritDataTypeFromItems(nameof(ItemsSource))]
+ public IBinding? CommandBinding
+ {
+ get => GetValue(CommandBindingProperty);
+ set => SetValue(CommandBindingProperty, value);
+ }
+
+ public static readonly StyledProperty CommandParameterBindingProperty = AvaloniaProperty.Register(
+ nameof(CommandParameterBinding));
+
+ [AssignBinding]
+ [InheritDataTypeFromItems(nameof(ItemsSource))]
+ public IBinding? CommandParameterBinding
+ {
+ get => GetValue(CommandParameterBindingProperty);
+ set => SetValue(CommandParameterBindingProperty, value);
+ }
+
+ public static readonly StyledProperty ContentBindingProperty = AvaloniaProperty.Register(
+ nameof(ContentBinding));
+
+ [AssignBinding]
+ [InheritDataTypeFromItems(nameof(ItemsSource))]
+ public IBinding? ContentBinding
+ {
+ get => GetValue(ContentBindingProperty);
+ set => SetValue(ContentBindingProperty, value);
+ }
+
+
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
recycleKey = null;
@@ -20,4 +55,28 @@ public class ButtonGroup: ItemsControl
{
return new Button();
}
+
+ protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
+ {
+ base.PrepareContainerForItemOverride(container, item, index);
+ if(container is Button button)
+ {
+ if ( CommandBinding is not null)
+ {
+ button[!Button.CommandProperty] = CommandBinding;
+ }
+ if ( CommandParameterBinding is not null)
+ {
+ button[!Button.CommandParameterProperty] = CommandParameterBinding;
+ }
+ if ( ContentBinding is not null)
+ {
+ button[!Button.ContentProperty] = ContentBinding;
+ }
+ if (ItemTemplate is not null)
+ {
+ button.ContentTemplate = ItemTemplate;
+ }
+ }
+ }
}
\ No newline at end of file