HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

ButtonGroup ItemsSource does not work

Open Joe-Fernico opened this issue 3 months ago • 0 comments

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

Image

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

Joe-Fernico avatar Sep 17 '25 15:09 Joe-Fernico