This is a migrated thread and some comments may be shown as answers.

ClearCommand binding

6 Answers 229 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Wei
Top achievements
Rank 1
Wei asked on 18 Dec 2013, 04:58 PM
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">

6 Answers, 1 is accepted

Sort by
0
Wei
Top achievements
Rank 1
answered on 19 Dec 2013, 08:47 PM
nobody having the same issue?
0
Petar Mladenov
Telerik team
answered on 21 Dec 2013, 09:20 AM
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 >>
0
Wei
Top achievements
Rank 1
answered on 23 Dec 2013, 11:03 PM
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.
0
Petar Mladenov
Telerik team
answered on 26 Dec 2013, 08:19 AM
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 >>
0
Wei
Top achievements
Rank 1
answered on 02 Jan 2014, 03:58 PM
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?
0
Petar Mladenov
Telerik team
answered on 07 Jan 2014, 12:11 PM
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 >>
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Wei
Top achievements
Rank 1
Answers by
Wei
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or