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