HandyControl
HandyControl copied to clipboard
ButtonGroup ItemsSource does not work
Describe the bug
ButtonGroup works fine if you add buttons manually, however I want to use the ItemsSource property to bind to a list on my view model to use dynamically generate the buttons. However the ButtonGroup.OnRender method casts each item to a ButtonBase, which if using ItemsSource binding, will throw an error
Steps to reproduce the bug
<hc:ButtonGroup Style="{StaticResource ButtonGroupSolid}"
Effect="{StaticResource DropShadowBrush}"
ItemsSource="{Binding DateRanges}">
<hc:ButtonGroup.ItemTemplate>
<DataTemplate>
<RadioButton Content="{Binding Name}"
GroupName="DateRangeGroup" />
</DataTemplate>
</hc:ButtonGroup.ItemTemplate>
</hc:ButtonGroup>
View Model:
public class MainViewModel
{
public ObservableCollection<DateRange> DateRanges {get;}
}
DateRange class:
public class DateRange
{
public string Name {get;}
}
Expected behavior
A dynamically created button group from the binding of ItemsSource
Screenshots
No response
NuGet package version
HandyControl 3.5.1
IDE
Visual Studio 2022
Framework type
.Net 9.0
Windows version
Windows 11 (22000)
Additional context
No response