Button Command binding in HeaderTemplate

7 posts, 0 answers
  1. Muhammad Irfan
    Muhammad Irfan avatar
    18 posts
    Member since:
    Jan 2010

    Posted 11 Aug 2011 Link to this post

    Hello All,
    I am trying to add a button in RadWinodw Title bar using its HeaderTemplate. Although button is visible on Title but its command is not properly binding and getting following error in Output window.
    BindingExpression path error: 'SaveCommand' property not found on 'object' ''String' (HashCode=1384875945)'. BindingExpression:Path=SaveCommand; DataItem='String' (HashCode=1384875945); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')

    Here is my XAML portion.
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="btn" Content="button" Command="{Binding Path=SaveCommand}" />               

    Here is my SaveCommand property in my ViewModel object.
    private DelegateCommand _saveCommand;
            public ICommand SaveCommand
                    if(_saveCommand == null)
                        _saveCommand = new DelegateCommand(param => SaveIndicator(), param => CanSaveIndicator());
                    return _saveCommand;
            public void SaveIndicator()
            protected bool CanSaveIndicator()
                if (eAppState == AppState.Fresh)
                    return false;
                return true;
    And here is how I am creating view and assigning its DataContext.
    InterpolatedIndicators.AddEditIndicators view = new InterpolatedIndicators.AddEditIndicators();
                view.DataContext = new InterpolatedIndicators.AddEditIndicatorsViewModel();
                view.Owner = this;

    Kindly note that when I am placing this button in Window Content section, then Command binding is working fine.
    I have also tried to set its RelativeSource using following code
    <Button x:Name="btn" Content="button" Command="{Binding Path=DataContext.SaveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
    But still it does not work.

    Any help please.
  2. Miroslav Nedyalkov
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 11 Aug 2011 Link to this post

    Hi Muhammad,

     The DataContext in the HeaderTemplate of the RadWindow control is its Header, so in order for this to work you need to set the Header of the Window to be your view-model. Another approach could be to use the RelativeSource property of the Binding like you do when you place the button in the content of the Window control, but the AncestorType should be telerik:RadWindow.

    Hope this helps.

    Kind regards,
    Miroslav Nedyalkov
    the Telerik team

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

  3. Muhammad Irfan
    Muhammad Irfan avatar
    18 posts
    Member since:
    Jan 2010

    Posted 16 Aug 2011 Link to this post

    Thank you Miroslav for your response. Yes binding is working when I changed AncestorType to telerik:RadWindow.
    But now I am facing another problem that button is not firing its click event. Kindly note that CanExecute is working fine, as button is enabling/disabling but when it is enabled (i.e. ready to click), I can't press on this button (and its click event can't fire). It looks that button on Telerik Window title is not actually behaving like button but acting like a label.

    Kindly help.

  4. Muhammad Irfan
    Muhammad Irfan avatar
    18 posts
    Member since:
    Jan 2010

    Posted 16 Aug 2011 Link to this post

    I found a solution of my question in the form of "IsHeaderHitTestVisible" property.
    Thanks anyways.....
  5. Boris
    Boris avatar
    2 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    Had the same problem with an image in the title. Solved it by setting:
  6. David
    David avatar
    6 posts
    Member since:
    Jun 2013

    Posted 16 Oct 2013 Link to this post

    Where did you set the "IsHeaderHitTestVisible" ?

  7. Kalin
    Kalin avatar
    1283 posts

    Posted 21 Oct 2013 Link to this post

    Hi David,

    The IsHeaderHitTestVisible property has been replaced with the attached property - telerik:WindowHost.HitTestable which should be set on the clickable element.

    Hope this helps. If you have any other questions let us know.

    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