无法使用 MahApps MetroWindow 在 Caliburn.Micro Conductor View 中更改标题

Not being able to change Title in a Caliburn.Micro Conductor View using MahApps MetroWindow

我是这样做的:

<Controls:MetroWindow x:Class="BS.Expert.Client.App.Views.ShellView"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    ShowTitleBar="True"
    Title="My Title">

问题是,这同时是主要 window 上定义的主要导体,我用它控制通过其他 windows 的导航,所以我无法从 MetroWindow 继承至少尝试更改 ViewModel 中的标题:

public class ShellViewModel : Conductor<IScreen>.Collection.OneActive, IShell
{
    public ShellViewModel()
    {
        #region mahApps Theme Loading

        var theme = ThemeManager.DetectAppStyle(Application.Current);
        var appTheme = ThemeManager.GetAppTheme(App.Configuration.Theme);
        ThemeManager.ChangeAppStyle(Application.Current, theme.Item2, appTheme);

        #endregion
        //TODO: Changing Title here is not possible ((MetroWindow)this).Title = "No way";
        // Tudo bem na seguinte liña
        LocalizeDictionary.Instance.Culture = new System.Globalization.CultureInfo("pt-BR");
        ShowPageOne();
    }

    public void ShowPageOne()
    {
        ActivateItem(new PageOneViewModel());
    }
}

如何更改标题?

当使用 MVVM 模式时,你不应该像这样直接在视图模型中尝试在视图上设置任何东西。而是使用数据绑定来完成此操作。

所以你的 ShellViewModel 上会有一个 属性 类似的东西:

public string MyTitle
{
    get { return _myTitle; }
    set
    {
        _myTitle = value;
        //Insert your property change code here (not sure of the caliburn micro version)
    }
}

在你的 window xaml 中它会是这样的:

<Controls:MetroWindow
    Title="{Binding MyTitle}"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    ...
    >