Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MaskedTextBox > Bind ICommand to InputBindings on RadMaskedTextBox

Not answered Bind ICommand to InputBindings on RadMaskedTextBox

Feed from this thread
  • Andy H Andy H's avatar

    Posted on Jun 28, 2011 (permalink)

    I have a Google-type search box (RadMaskedTextBox) in a Silverlight application and would like the search action to be triggered as soon as the user hits enter.

    I am using MVVM and have tried to achieve this behaviour as follows:

    XAML:

    <telerik:RadMaskedTextBox Value="{Binding SearchString, Mode=TwoWay}"
                      EmptyContent="Search (min. 3 characters)">
        <telerik:CommandManager.InputBindings>
            <telerik:KeyBinding Command="{Binding SearchCommand}" Key="Enter" />
        </telerik:CommandManager.InputBindings>
    </telerik:RadMaskedTextBox>
    <telerik:RadButton Command="{Binding Path=SearchCommand}"
                 Content="Search"/>

    C#:
    private ICommand _searchCommand;
    public ICommand SearchCommand
    {
        get
        {
            if (_searchCommand == null)
            {
                _searchCommand = new DelegateCommand<object>(OnSearchCommand);
            }
            return (_searchCommand);
        }
    }

    When the app runs, I get this error message:
    Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Windows.Input.ICommand'.

    Any ideas?

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Jul 1, 2011 (permalink)

    Hi Andy H,

    The problem here is that KeyBinding.Command is not a dependency property, so it does not support data binding. Feel free to ask if you need further assistance.


    Kind regards,
    Petar Mladenov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Shane avatar

    Posted on Oct 3, 2011 (permalink)

    was there ever a solution provided for this? Having the same exact same issue.

    Reply

  • Alex Fidanov Alex Fidanov admin's avatar

    Posted on Oct 6, 2011 (permalink)

    Hello Shane,

    The Command property of the InputBinding uses a TypeConverter to find the type of the binding. For this, you need to use the following syntax :

    <telerik:RadMaskedTextBox>
         <telerik:CommandManager.InputBindings>
             <telerik:InputBindingCollection>
                 <telerik:KeyBinding Command="local:MyCommands.MyCommand" Key="Enter"/>
             </telerik:InputBindingCollection>
         </telerik:CommandManager.InputBindings>
     </telerik:RadMaskedTextBox>
    The MyCommand command is declared in a static class MyCommands as follows:

    public static class MyCommands
    {
        public static RoutedUICommand MyCommand { get; private set; }
     
        static MyCommands()
        {
            MyCommand = new RoutedUICommand("description", "MyCommand", typeof(MyCommands));
        }
    }
    And finally, you can register bindings to that command :

    CommandBinding b = new CommandBinding(MyCommands.MyCommand, CommandBinding_Executed, CommandBinding_CanExecute);
    CommandManager.RegisterClassCommandBinding(typeof(MainPage), b);


    Greetings,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MaskedTextBox > Bind ICommand to InputBindings on RadMaskedTextBox
Related resources for "Bind ICommand to InputBindings on RadMaskedTextBox"

Silverlight MaskedTextBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]