Custom Command State

3 posts, 1 answers
  1. Jose Ramon
    Jose Ramon avatar
    2 posts
    Member since:
    Sep 2013

    Posted 23 Sep 2013 Link to this post


    I have a problem whith the CustomCommand of the RadMap. 

    I use a CustomCommand for Add or remove a WMS provider. 

    My problem is the CustomCommand State, when i click the button of the custom command, it is highlighted (this is ok), but when i clicking the button for second time to disable, the button remains highlighted.

    Another problem, when i click the button of the custom command, it is highlighted (this is ok), but when i clik another button (ex. road view), the button not remains highlighted.

    ¿How I can control this?

    Thanks and sorry for my english.
  2. Answer
    Andrey avatar
    1681 posts

    Posted 25 Sep 2013 Link to this post

    Hi Jose,

    It is hard to say about particular causes of these problems without your code or your solution.

    1. A reason of this behavior could be in the case when you use for example the RadRadioButton in DataTemplate for your custom command. I think it is correct to use the RadToggleButton for command of this type.

    2. It looks like you added your custom command to the BingMapProvider. In this case you should restore a state of your command when the mode of BingMapProvider is changed.

    The sample code is below.

    <Window x:Class="CustomCommandExample.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid x:Name="LayoutRoot">
                <DataTemplate x:Key="CustomCommandDataTemplate">
                    <telerik:RadToggleButton Command="{Binding Path=Command}"
                                    CommandParameter="{Binding CommandParameter}"
                                    IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <GradientStop Color="White"/>
                                <GradientStop Color="#FFD4D4D4" Offset="1"/>
                                <GradientStop Color="Gainsboro" Offset="0.5"/>
                                <GradientStop Color="#FFADADAD" Offset="0.51"/>
                        <Grid HorizontalAlignment="Stretch">
                                <ColumnDefinition />
                                <ColumnDefinition Width="32" />
                            <TextBlock Text="{Binding Path=Command.Text}"
                                  FontWeight="Bold" />
                            <Image Grid.Column="1" Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <BitmapImage UriSource="{Binding ImageUri}" />
            <telerik:RadMap x:Name="RadMap1">


    public partial class MainWindow : Window
        private string VEKey = "xxx-yyy-zzz";
        private BingMapProvider provider;
        private bool isShowWMSSelected = false;
        private CommandDescription commandDescription;
        public MainWindow()
        private void SetProvider()
            this.provider = new BingMapProvider(MapMode.Aerial, true, this.VEKey);
            this.provider.MapSourceChanged += provider_MapSourceChanged;
            this.RadMap1.Provider = provider;
        void provider_MapSourceChanged(object sender, MapSourceChangedEventArgs e)
            commandDescription.IsSelected = isShowWMSSelected;
        private void AddCustomCommandAction(BingMapProvider provider)
            string commandText = "Show WMS";
            string commandName = "ShowWMS";
            this.commandDescription = new CommandDescription();
            this.commandDescription.Command = new RoutedUICommand(commandText, commandName, typeof(BingMapProvider));
            this.commandDescription.DataTemplate = this.LayoutRoot.Resources["CustomCommandDataTemplate"] as DataTemplate;
            this.commandDescription.ImageUri = new Uri("/CustomCommandExample;component/Resources/Images/CommandImage.png", UriKind.RelativeOrAbsolute);
            CommandBinding commandBinding = new CommandBinding(commandDescription.Command, ExecuteCustomCommand);
        private void ExecuteCustomCommand(object sender, ExecutedRoutedEventArgs e)
            this.isShowWMSSelected = !this.isShowWMSSelected;
            if (this.isShowWMSSelected)
                // Add WMS provider
                // Remove WMS provider

    Andrey Murzov

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Jose Ramon
    Jose Ramon avatar
    2 posts
    Member since:
    Sep 2013

    Posted 26 Sep 2013 Link to this post

    Thanks for your answer!!!! It is very helpful!
Back to Top