0

this code is not working. I want to add button group instead radio button.. there is three buttons. all three buttons are same color(blue). when user click on 1st button it will change that button color as red. But when user click on second button, first button must turn into blue color and clicked button(2nd button) must turn in to red. In my code that's not change. this is my code. please Help me

    <UserControl>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Background" Value="Green"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="1">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsFocused" Value="True">
                    <Setter Property="Background" Value="Red"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl>

    <Button  Command="{Binding LanguageChangeCommand}" CommandParameter="English" Content="English" Width="80" Grid.Column="2" Grid.Row="3"  Margin="8,15,162,21" Grid.ColumnSpan="2" />
    <Button  Command="{Binding LanguageChangeCommand}" CommandParameter="Sinhala" Content="සිංහල" Width="80" Grid.Column="3" Grid.Row="3"  Margin="78,15,77,21" />
    <Button Command="{Binding LanguageChangeCommand}"  CommandParameter="Tamil" Content="தமிழ்" Width="80" Grid.Column="3" Grid.Row="3" Margin="165,15,10,21" Grid.ColumnSpan="2"/>
  • I think you can find your answer [Here](https://stackoverflow.com/questions/2362641/how-to-get-a-group-of-toggle-buttons-to-act-like-radio-buttons-in-wpf) and [Here](https://stackoverflow.com/questions/42089140/style-wpf-radio-button-as-toggle-button-with-correct-isenabled-behaviour). Second solution seems to be what you are looking for. – Vali Maties Jan 03 '22 at 11:57
  • @_Vali Maties I want to add normal buttons – Hasith Yoman Jan 03 '22 at 12:52
  • ToogleButtons do the job what you want. If you don't want it, then you must use a custom Button with a bool DependencyProperty attached to this Button and a GroupName DependencyProperty. (but this is what ToogleButton do itself) Use Style triggers to check this property and change background according to it. – Vali Maties Jan 04 '22 at 09:41
  • Or you can add a RadioButton to that custom button, and in Style Trigger check if radio button's IsChecked is true, not IsFocused of button. But it is not a good approach. – Vali Maties Jan 04 '22 at 09:50

0 Answers0