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

HeaderTemplate Binding

2 Answers 496 Views
Window
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Peter asked on 02 Dec 2020, 01:43 PM
Hello,

I want to bind some property from my ViewModel to a RadWindow.HeaderTemplate. My approach seems not to work. Can you help me with this?

 
<telerik:RadWindow.HeaderTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <Image Width="18" Source="Resources/ICO/CANsymEdit.ico" Stretch="Uniform" />
            <!--<ContentPresenter Content="{Binding}" Margin="5,0" />-->
            <TextBlock Text="{Binding DataContext.ActiveDocument, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" VerticalAlignment="Center" Margin="5,0" />
        </StackPanel>
    </DataTemplate>
</telerik:RadWindow.HeaderTemplate>

 

regards,

Tobias

2 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 03 Dec 2020, 11:45 AM

Hello Tobias,

Thank you for the shared code snippet.

It seems that you are using a RelativeSource Binding pointing to an AncestorType - Window. Note, that if you want to target the RadWindow, you should use "AncestorType={x:Type telerik:RadWindow}".

That said, if "ActiveDocument" is a property of the object that is the DataContext of the RadWindow, you can use the following approach:

<telerik:RadWindow Header="{Binding ActiveDocument}">
    <telerik:RadWindow.HeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding }" VerticalAlignment="Center" Margin="5,0" />
            </StackPanel>
        </DataTemplate>
    </telerik:RadWindow.HeaderTemplate>
 
</telerik:RadWindow>

Note, that I am binding the Header property of the RadWindow, which becomes the DataContext inside the HeaderTemplate. That is a common pattern for all X/XTemplate properties in WPF. 

I hope you find this information helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 03 Dec 2020, 01:53 PM
that works for me, thanks a lot!
Tags
Window
Asked by
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Vladimir Stoyanov
Telerik team
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or