Reputation: 42991
I'm using the well known technique of styling a list box to look like a radio button group. The style presents a BulletDecorator for each item in the list. In order to do this I need to reference a specific theme assembly such as PresentationFramework.Aero.dll, and then explicitly use that in my style.
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
<BulletDecorator.Bullet>
<theme:BulletChrome
Background="{TemplateBinding Control.Background}"
BorderBrush="{TemplateBinding Control.BorderBrush}"
IsRound="True"
RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}"
IsChecked="{TemplateBinding ListBoxItem.IsSelected}" />
</BulletDecorator.Bullet>
Is there a way to create a BulletDecorator which is styled using the current or default theme, so that I don't need to reference an explicit theme?
Upvotes: 0
Views: 919
Reputation: 292465
You don't need to recreate the RadioButton
template... why don't you just use a RadioButton
in the ItemContainerStyle
?
<Style x:Key="RadioButtonGroup" TargetType="ListBox">
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<RadioButton IsChecked="{TemplateBinding IsSelected}" Content="{TemplateBinding Content}" GroupName="ListBoxItems" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
Note that there's an issue with this approach: if you use this style for several ListBoxes
in the same window, all RadioButtons
will be mutually exclusive, because they will share the same GroupName
. See this article for a workaround.
Upvotes: 1