Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm doing like so:

<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">

The thing is that this is at the same time a defined main conductor on the main window with which I control navigation through other windows, so I'm not able to inherit from MetroWindow to at least trying change the title in the 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());
    }
}

How should I change the title?

like image 923
Morty Avatar asked Jul 21 '15 13:07

Morty


1 Answers

When using the MVVM pattern you should never try to set anything on the view directly in the view model like this. Instead using data binding to accomplish this.

So you would have a property on your ShellViewModel with something like:

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

and in your window xaml it would be something like:

<Controls:MetroWindow
    Title="{Binding MyTitle}"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    ...
    >
like image 54
TylerReid Avatar answered Oct 16 '22 06:10

TylerReid