ClearCommand binding

7 posts, 0 answers
  1. Wei
    Wei avatar
    4 posts
    Member since:
    Jul 2013

    Posted 18 Dec 2013 Link to this post

    I tried to bind ClearCommand with my own command, but the handling method never fires, instead it seems the original handler still fires and clears the input. Does binding works on ClearCommand?

    Here is my view model code:
    public DelegateCommand ClearCriteriaCommand { get; set; }

    and setup:
    ClearCriteriaCommand = new DelegateCommand(o => ClearCriteria());

    here is the binding:
    <RadMaskedTextInput Name="txtSearchField" Value="{Binding Path=SearchCriteria, Mode=TwoWay}" ClearCommand="{Binding Path=ClearCriteriaCommand}" AcceptsReturn="False" EmptyContent="Enter Search Term">
  2. Wei
    Wei avatar
    4 posts
    Member since:
    Jul 2013

    Posted 19 Dec 2013 Link to this post

    nobody having the same issue?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Dec 2013 Link to this post

    Hi Wei,

    You can find attached a test project in which we successfully bind the ClearCommand of the MaskedInput to a DelegateCommand from our ViewModel. Could please check it out and let us know if it helps you or if we have missed something ? On the other hand, you can check out your output for Binding / Binding ExpressionErrors that may be the reason for your command not firing.

    We hope this helps you proceed further.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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 >>
  5. Wei
    Wei avatar
    4 posts
    Member since:
    Jul 2013

    Posted 23 Dec 2013 Link to this post

    Thank you for your response, now I think I have a clearer setup that ClearCommand binding doesn't work. It's when it is used inside a template. Exchange the MainWindow.xaml content that you sent with the code below:
    <Window x:Class="WpfApplication1.MainWindow"
            xmlns:telerikChromes="clr-namespace:Telerik.Windows.Controls.Chromes;assembly=Telerik.Windows.Controls"
            xmlns:maskedInput="clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input"
            xmlns:local="clr-namespace:WpfApplication1"
            Title="MainWindow" Height="350" Width="525">
      <Window.Resources>
        <DataTemplate x:Key="Template_Search" DataType="{x:Type local:DataItem}">
          <StackPanel>
            <telerik:RadMaskedTextInput Name="txtSearchField" ClearCommand="{Binding ClearCriteriaCommand}" />
            <Button Command="{Binding ClearCriteriaCommand}" Content="Click"></Button>
          </StackPanel>
        </DataTemplate>
      </Window.Resources>
      <StackPanel>
        <ContentControl Content="{Binding}">
          <ContentControl.Template>
            <ControlTemplate TargetType="{x:Type ContentControl}">
              <ContentPresenter ContentTemplate="{StaticResource Template_Search}" />
            </ControlTemplate>
          </ContentControl.Template>
        </ContentControl>
        <telerik:RadMaskedTextInput ClearCommand="{Binding Path=ClearCriteriaCommand}" />
        <Button Command="{Binding ClearCriteriaCommand}" Content="Click"></Button>
      </StackPanel>
    </Window>

    basically we have 2 sets of RadMaskedTextInput followed by a button, the first set is inside a template and the second set is not. The clear button and button command on 2nd set work, as well as the button command in the first set. The only thing that doesn't work is the clear command binding for RadMaskedTextInput under data template.
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 26 Dec 2013 Link to this post

    Hello Wei,

    We reproduced this issue and we investigated it successfully. The ClearCommand of the RadMaskedInputBase class (base class for all MaskedInput controls) is set in the constructor of the control locally. This means that in normal scenario (when the control is not in a foreign control template), setting the ClearCommand like so - {Binding ClearCriteriaCommand} succeeds because it is a second local setting of the property ClearCommand- and the second setting overwrites the first one from the Style.
    However, when the MaskedInput is in the ControlTemplate of the ContentControl, the BaseValueSource of the ClearCommandProperty is "ParentTemplate" - you can test it like so in the Loaded handler of the MaskedInput:
    DependencyPropertyHelper.GetValueSource(sender as RadMaskedInputBase, RadMaskedInputBase.ClearCommandProperty)
    and this will return:
    {System.Windows.ValueSource}
        BaseValueSource: ParentTemplate
        IsAnimated: false
        IsCoerced: false
        IsCurrent: false
        IsExpression: true
    And since the BaseValueSource is ParentTemplate , the local set command in the constructor has a bigger priority (having in mind the dependency property precedence list).

    We hope these explanations can help you proceed further. Do you think you can re-design your app to avoid using a custom ControlTemplate for a ContentControl ?

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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 >>
  7. Wei
    Wei avatar
    4 posts
    Member since:
    Jul 2013

    Posted 02 Jan 2014 Link to this post

    Hi Petar,

    Thank you for your explanation, so I guess we will have to get rid of the template in order to solve this. Does Telerik plan to change this behavior in future?
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Jan 2014 Link to this post

    Hello Wei,

    Yes you can consider redesigning you app to avoid using MaskedInput in ContentTemplate of ContentPresenter located in ControlTemplate. We have currently no plans for changing the way ClearCommand is initialized in the MaskedInput components.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready