none
Buttons that act like radio buttons

    Question

  • How do I make them? I have a wrappanel that will have all the buttons for my vector graphics editor - draw rectangle, draw segment, move shape, resize shape, etc. But how do I make them act like radio buttons? Preferably with possibility to have all of them to be toggled off.
    Tuesday, March 21, 2017 3:16 AM

All replies

  • Hi Eugene,

    I think you might have a try for this:

    <Window
        x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="MainWindow"
        Width="525"
        Height="350"
        mc:Ignorable="d">
        <Window.Resources>
            <ControlTemplate x:Key="RadioButtonControlTemplate" TargetType="{x:Type RadioButton}">
                <ToggleButton Content="{Binding Content, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsChecked, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </ControlTemplate>
        </Window.Resources>
        <Grid>
            <StackPanel>
                <RadioButton Content="Rectangle" Template="{DynamicResource RadioButtonControlTemplate}" />
                <RadioButton Content="Line" Template="{DynamicResource RadioButtonControlTemplate}" />
                <RadioButton Content="Circle" Template="{DynamicResource RadioButtonControlTemplate}" />
            </StackPanel>
        </Grid>
    </Window>
    

    The key is to make RadioButton use the ToggleButton as its control template, that's all.


    Ouch Liu , Developer ≈ Designer


    • Edited by Ouch Liu Tuesday, March 21, 2017 3:42 AM
    Tuesday, March 21, 2017 3:34 AM
  • Generally speaking, just handle the click event (and other relevant events) and when one control is clicked, unselect the one that is selected.


    Sam Hobbs
    SimpleSamples.Info

    Tuesday, March 28, 2017 4:38 PM