6

New to Caliburn and WPF MVVM, so I may be overlooking something pretty simple and I couldn't find anything searching the web.

Set up a simple wpf project with Caliburn.Micro. Set window title in ShellView.xaml. Works fine. Main MetroWindow displays the title as expcted.

Works fine:

[Export(typeof (IShell))]
public class ShellViewModel : PropertyChangedBased, IShell
{}

But change to:

[Export(typeof (IShell))]
public class ShellViewModel : Conductor<object>
{}

and Window title is the fully qualified name of this ViewModel. ANy help would be appreciated. Thanks.

Claudio P
  • 2,133
  • 3
  • 25
  • 45
Dan G.
  • 529
  • 8
  • 21

2 Answers2

11

You can use it like this:

[Export(typeof (IShell))]
public class ShellViewModel : Conductor<IScreen>
{
    public ShellViewModel()
    {
        DisplayName = "Your window title";
    }
}

In my repository you can find some applications in WPF using Caliburn.Micro, for example:

Wojciech Kulik
  • 7,823
  • 6
  • 41
  • 67
  • Thanks for link and suggestion. Still the same. Should have mentioned that I'm using Caliburn.Micro 2.02. Noticed in your bootstrapper you're using 1.5.2. – Dan G. Apr 15 '15 at 00:54
  • Could you show your project? I prepared a sample app with the new version and it works. Have you seen this [documentation](https://caliburnmicro.codeplex.com/wikipage?title=Screens,%20Conductors%20and%20Composition)? (I have to go, i'll try to help tomorrow). – Wojciech Kulik Apr 15 '15 at 01:05
1

Thanks to Wojciech for pointing me in the right direction.

When ShellViewModel is inheriting PropertyChangeBase and IShell, setting the Title = "Window Title" in ShellView.xaml works. But, when using Caliburn.Micro 2.0.2 and inheriting from Conductor (single screen conductor) the window title is overwritten with the fully-qualified name of the view model (in my case):

FBAGOLDEVALUATOR.APP.VIEWMODELS.SHELLVIEWMODEL

This looks like bug in Caliburn.Micro v2.02, unless I'm missing something.

The workaround: Bind the Title property of the window in .xaml to a public property in the ViewModel. The .xaml line:

Title="{Binding Path=DisplayTitle, Mode=OneWay}" 

The property in ShellViewModel.cs:

    private string _displayTitle;
    public String DisplayTitle
    {
        get
        {
            return _displayTitle;
        }
        set
        {
            if (value.Equals(_displayTitle)) return;
            _displayTitle = value;
            NotifyOfPropertyChange(() => DisplayName);
        }
    }

Then set it in the ShellViewModel constructor:

DisplayTitle = "FBA Gold Evaluator";

That seems to work.

Dan G.
  • 529
  • 8
  • 21
  • I edited your answer adding a small fix to prevent null reference exception in setter ;-). Are you sure that setting "DisplayName" doesn't work? Did you remove Title from XAML first? – Wojciech Kulik Apr 15 '15 at 01:32
  • You're right! Removing the Title from XAML and setting DisplayName = "New Title" in the ModelView constructor works great. I totally missed that. I guess trying to learn XAML, WPF, MVVM and Caliburn.Micro at the same time is a bad idea. Sorry I jumped the gun. How do I re-mark you're entry as the answer? Thanks. – Dan G. Apr 15 '15 at 01:41
  • Just checked yours as the answer. Thanks again. – Dan G. Apr 15 '15 at 01:42