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

Button Command binding in HeaderTemplate

6 Answers 118 Views
Window
This is a migrated thread and some comments may be shown as answers.
Muhammad Irfan
Top achievements
Rank 1
Muhammad Irfan asked on 11 Aug 2011, 11:43 AM
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.
<telerik:RadWindow.HeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Button x:Name="btn" Content="button" Command="{Binding Path=SaveCommand}" />               
            </StackPanel>
        </DataTemplate>
    </telerik:RadWindow.HeaderTemplate>

Here is my SaveCommand property in my ViewModel object.
private DelegateCommand _saveCommand;
        public ICommand SaveCommand
        {
            get
            {
                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;
            view.ShowDialog();

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.

6 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 11 Aug 2011, 01:20 PM
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 >>

0
Muhammad Irfan
Top achievements
Rank 1
answered on 16 Aug 2011, 11:17 AM
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.

0
Muhammad Irfan
Top achievements
Rank 1
answered on 16 Aug 2011, 11:30 AM
I found a solution of my question in the form of "IsHeaderHitTestVisible" property.
Thanks anyways.....
0
Boris
Top achievements
Rank 1
answered on 30 Jan 2012, 09:42 PM
Had the same problem with an image in the title. Solved it by setting:
telerik:WindowHost.HitTestable="True"
0
David
Top achievements
Rank 1
answered on 16 Oct 2013, 08:49 AM
Where did you set the "IsHeaderHitTestVisible" ?

0
Kalin
Telerik team
answered on 21 Oct 2013, 08:25 AM
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.

Regards,
Kalin
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
Window
Asked by
Muhammad Irfan
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Muhammad Irfan
Top achievements
Rank 1
Boris
Top achievements
Rank 1
David
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or