Note that there are some explanatory texts on larger screens.

plurals
  1. POXAML to add header to radio button
    text
    copied!<p>So with a lot of looking around I am hoping to make a GroupBox that acts like a Radio button. The header section would act as the bullet. I took some code from this question</p> <p><a href="https://stackoverflow.com/questions/9361903/styling-a-groupbox">Styling a GroupBox</a></p> <p>that is how I want it to look. But I want to have it as a Radio button. So I put in this code (mind you I've only been doing WPF for a week or 2 now)</p> <pre><code> &lt;Style TargetType="{x:Type RadioButton}" &gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type RadioButton}"&gt; &lt;BulletDecorator&gt; &lt;BulletDecorator.Bullet&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Border x:Name="SelectedBorder" Grid.Row="0" Margin="4" BorderBrush="Black" BorderThickness="1" Background="#25A0DA"&gt; &lt;Label x:Name="SelectedLabel" Foreground="Wheat"&gt; &lt;ContentPresenter Margin="4" /&gt; &lt;/Label&gt; &lt;/Border&gt; &lt;Border&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/BulletDecorator.Bullet&gt; &lt;/BulletDecorator&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsChecked" Value="true"&gt; &lt;Setter TargetName="SelectedBorder" Property="Background" Value="PaleGreen"/&gt; &lt;Setter TargetName="SelectedLabel" Property="Foreground" Value="Black" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>I have a feeling that I can add a label to the second row of my grid, but then I don't know how to access it. I have that template in a test project in the Window.Resources section (I plan on moving it to a resource dictionary in my main project) the xaml for my window is this</p> <pre><code>&lt;Grid&gt; &lt;GroupBox Name="grpDoor" Margin ="8" Grid.Row="0" Grid.Column="0"&gt; &lt;GroupBox.Header&gt; WPF RadioButton Template &lt;/GroupBox.Header&gt; &lt;StackPanel Margin ="8"&gt; &lt;RadioButton FontSize="15" Content="Dhaka" Margin="4" IsChecked="False"/&gt; &lt;RadioButton FontSize="15" Content="Munshiganj" Margin="4" IsChecked="True" /&gt; &lt;RadioButton FontSize="15" Content="Gazipur" Margin="4" IsChecked="False" /&gt; &lt;/StackPanel&gt; &lt;/GroupBox&gt; &lt;/Grid&gt; </code></pre> <p>I then hoping for something like this (not sure how I'd do it yet though)</p> <pre><code>&lt;Grid&gt; &lt;GroupBox Name="grpDoor" Margin ="8" Grid.Row="0" Grid.Column="0"&gt; &lt;GroupBox.Header&gt; WPF RadioButton Template &lt;/GroupBox.Header&gt; &lt;StackPanel Margin ="8"&gt; &lt;RadioButton FontSize="15" Content="Dhaka" Margin="4" IsChecked="False"&gt; &lt;RadioButton.Description&gt; This is a description that would show under my Header &lt;/RadioButton.Description&gt; &lt;/RadioButton&gt; &lt;RadioButton FontSize="15" Content="Munshiganj" Margin="4" IsChecked="True"&gt; &lt;RadioButton.Description&gt; This is a description that would show under my Header &lt;/RadioButton.Description&gt; &lt;/RadioButton&gt; &lt;RadioButton FontSize="15" Content="Gazipur" Margin="4" IsChecked="False"&gt; &lt;RadioButton.Description&gt; This is a description that would show under my Header &lt;/RadioButton.Description&gt; &lt;/RadioButton&gt; &lt;/StackPanel&gt; &lt;/GroupBox&gt; &lt;/Grid&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload