|
@@ -50,7 +50,7 @@ public partial class ButtonStrip : TemplatedControl
|
|
|
public ObservableCollection<ButtonStripItem> Items
|
|
|
{
|
|
|
get => GetValue(ItemsProperty);
|
|
|
- private set => SetValue(ItemsProperty, value);
|
|
|
+ set => SetValue(ItemsProperty, value);
|
|
|
}
|
|
|
|
|
|
public ButtonStripItem? SelectedItem
|
|
@@ -67,6 +67,26 @@ public partial class ButtonStrip : TemplatedControl
|
|
|
|
|
|
public event EventHandler SelectionChanged;
|
|
|
|
|
|
+ static ButtonStrip()
|
|
|
+ {
|
|
|
+ ItemsProperty.Changed.AddClassHandler<ButtonStrip>(Items_Changed);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Items_Changed(ButtonStrip strip, AvaloniaPropertyChangedEventArgs args)
|
|
|
+ {
|
|
|
+ strip.LogicalChildren.Clear();
|
|
|
+ if (strip.Items is not null)
|
|
|
+ {
|
|
|
+ strip.SelectedItem = strip.Items.FirstOrDefault();
|
|
|
+
|
|
|
+ strip.LogicalChildren.AddRange(strip.Items);
|
|
|
+ foreach(var item in strip.Items)
|
|
|
+ {
|
|
|
+ item.Command = strip.ItemSelectedCommand;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public ButtonStrip()
|
|
|
{
|
|
|
Items = new();
|