Radbutton background color converters issue

2 posts, 0 answers
  1. Chandra Sekhar
    Chandra Sekhar avatar
    16 posts
    Member since:
    Sep 2016

    Posted 15 Apr Link to this post

    Hi,

    I would like to create and use a converter to change the background of a single selected button among the three buttons available. I don't want to handle a click event of the buttons and handle it from code behind and so tried different ways to create the converters, however it didn't work. Below I am providing a sample of my scenario. Any help would be greatly appreciated. Thank you.
     

    <StackPanel Grid.Row="0" HorizontalAlignment="Center" x:Name="FirstRowControl" Orientation="Horizontal" Margin="232,0,233,0">
    <telerik:RadButton Name="btn1" FontWeight="SemiBold" Margin="5" Content="Button 1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="25" BorderBrush="Black" Command="{Binding UpdateTabCommand}" >
    <telerik:RadButton.CommandParameter>
    <models:Tabs>Button1</models:Tabs>
    </telerik:RadButton.CommandParameter>
    </telerik:RadButton>
    <telerik:RadButton Name="btn2" FontWeight="SemiBold" Margin="5" Content="Button 2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="25" BorderBrush="Black" Command="{Binding UpdateTabCommand}" >
    <telerik:RadButton.CommandParameter>
    <models:Tabs>Button2</models:Tabs>
    </telerik:RadButton.CommandParameter>
    </telerik:RadButton>

    <telerik:RadButton Name="btn3" FontWeight="SemiBold" Margin="5" Content="Button 3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="180" Height="25" BorderBrush="Black" Command="{Binding UpdateTabCommand}" >
    <telerik:RadButton.CommandParameter>
    <models:Tabs>Button3</models:Tabs>
    </telerik:RadButton.CommandParameter>
    </telerik:RadButton>
    </StackPanel>

    Code in the VM:
     
    public DelegateCommand<Tabs?> UpdateTabCommand
    { get; }

    public Tabs SelectedTab
    {
    get { return base.GetProperty<PedpTabs>(defaultValueFactory: () => Tabs.Button1); }
    set { base.SetProperty(value); }
    }

    public enum Tabs
    {
    Button1,
    Button2,
    Button3
    }


    public ClassVM()
    {
    UpdateTabCommand = new DelegateCommand<Tabs?>(OnChangeTabExecute);
    }


    private void OnChangeTabExecute(PedpTabs? selectedTab)
    {
    this.SelectedTab = selectedTab ?? Tabs.StateChanges;
    }

    protected override void OnPropertyChanged(string propertyName)
    {
    base.OnPropertyChanged(propertyName);

    switch (propertyName)
    {
    case nameof(SelectedTab):
    OnTabChanged();
    break;
    }
    }

    private void OnTabChanged()
    {
    switch (SelectedTab)
    {
    case Tabs.Button1:
        MessageList = Messages2080;
        break;

    case Tabs.Button2:
    MessageList = Messages2088;
    break;
    case Tabs.Button3:
    MessageList = Messages2010;
    break;
    }
    }

    Thanks, Chand

     

     

     

     

  2. Dinko
    Admin
    Dinko avatar
    874 posts

    Posted 18 Apr Link to this post

    Hello Chandra Sekhar,

    Thank you for the provided code snippet.

    If I have correctly understood your scenario, you want to change the background of the button which was last clicked. If this is the case, I would suggest you to try using RadRadioButton instead. This way only one button from the group can be checked and will have a different background color. You can get familiar with this control in the Radio Button help article in our documentation.

    Give this suggestion a try and let me know if it works for you.

    Regards,
    Dinko
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top