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

Why can't I hard-code my RadWindow Header directly in xaml?

4 Answers 109 Views
Window
This is a migrated thread and some comments may be shown as answers.
Laurent
Top achievements
Rank 1
Laurent asked on 12 Oct 2020, 07:40 AM

Here's my setup:

I have an application view leveraging a caliburn bootstrapper (should be irrelevant for the issue):

<Application x:Class="TestApp.App"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:TestApp"
             xmlns:shell="clr-namespace:TestApp.Shell"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
 
                <ResourceDictionary>
                    <local:Bootstrapper x:Key="Bootstrapper" />
                </ResourceDictionary>
 
                <telerik:FluentResourceDictionary />
 
                <ResourceDictionary Source="/Telerik.Windows.Themes.Fluent;component/Themes/System.Windows.xaml" />
                <ResourceDictionary
                    Source="/Telerik.Windows.Themes.Fluent;component/Themes/Telerik.Windows.Controls.xaml" />
                <ResourceDictionary
                    Source="/Telerik.Windows.Themes.Fluent;component/Themes/telerik.windows.controls.input.xaml" />
                <ResourceDictionary
                    Source="/Telerik.Windows.Themes.Fluent;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
 
            </ResourceDictionary.MergedDictionaries>
 
            <Style TargetType="shell:ShellView" BasedOn="{StaticResource RadWindowStyle}" />
 
        </ResourceDictionary>
    </Application.Resources>
</Application>

Here's my application's shell view:

<telerik:RadWindow x:Class="TestApp.Shell.ShellView"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                   xmlns:testApp="clr-namespace:TestApp.Shell"
                   Width="800"
                   Height="475"
                   Header="Application title">
 
    <Grid>
 
    </Grid>
 
</telerik:RadWindow>

 

Note in the above code the Header="Application title". When I start that application, it shows the window shown in the attachment, i.e. a window with title "TestApp.Shell.ShellViewModel". If I, however, refactor that with the following binding

Header="{Binding Header}"

 

 

and add the Header property to my view model

using Caliburn.Micro;
 
namespace TestApp.Shell
{
    public class ShellViewModel : Conductor<IScreen>
    {
        public string Header => "Application title";
    }
}

 

then I see the correct application title.

Why can't I just hard-code my application title in my Window's xaml code? What am I doing wrong here?

4 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 14 Oct 2020, 07:03 AM

Hello Laurent,

Setting the Header property of RadWindow works properly without the Caliburn framework. It looks like the framework is overriding the window's header when using the Conductor<T> class for the window's view model. You can try setting the DisplayName of the ShellViewModel.

public ShellViewModel()
{
	DisplayName = "Your window title";
}

Regards,
Martin Ivanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Lorenz
Top achievements
Rank 1
answered on 15 Oct 2020, 05:23 AM

Dear Martin,

Thank your very much for this clarification! 

However, I will stick to my solution. Indeed, I am not a huge fan of calling virtual methods in my constructors. For me, this override of the Header with the view model's DisplayName is a hack on caliburn.micro's side. I'll open an issue there to ask why they do this.

For me, it is ok to bind with a property of my view model. I appreciate your answer in the sense that now I know why I need to do that. 

Best regards

0
Laurent
Top achievements
Rank 1
answered on 15 Oct 2020, 05:29 AM

In fact, using our own property like we do is the recommended way:

https://github.com/Caliburn-Micro/Caliburn.Micro/issues/178

0
Martin Ivanov
Telerik team
answered on 15 Oct 2020, 07:06 AM

Hello guys,

Thank you for sharing this information.

Regards,
Martin Ivanov
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/.

Tags
Window
Asked by
Laurent
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Lorenz
Top achievements
Rank 1
Laurent
Top achievements
Rank 1
Share this question
or