0

My question is exactly like in the title. I'm starting with Caliburn.Micro for MVVM approach (which also is new for me) and in every tutorial the first step is to remove the default MainWindow.xaml file and create a new UserControl file. Why is that? UserControl does not even accept a Title. Isn't it possible to build application using normal Windows? I already tried that, but with every launch I get error "Cannot find view for ViewModel", although both MainView.xaml and MainViewModel.cs are present. When I created a pair of USerControl and ViewModel for it, everything started to work as expected. So again, why Windows don't work? It wouldn't really be a problem, but I'm thinking that some additions like Modern UI themes for WPF might not work without a window. I'm not sure of that.

Probably one solution would be to display a defined UserControl View inside of a Window, but it's just a workaround.

Loreno
  • 668
  • 8
  • 26
  • 1
    Caliburn creates a window for you, and hosts your user control in it. It's the right approach. You can easily swap out user controls, or host multiple user controls in the same window. – Eternal21 Aug 14 '17 at 16:53
  • @Eternal21 Thanks, I didn't know. But what if I want to change some settings of my main window (like change title, icon, etc.)? – Loreno Aug 14 '17 at 17:48
  • Here's how you do it: https://claytonone.wordpress.com/2015/01/16/caliburn-micro-part-6-the-window-manager/ I recommend you go through that whole tutorial, it's good. – Eternal21 Aug 14 '17 at 18:56
  • @Eternal21 Yeah, I had already done this tutorial, it is good, like you've said. What about the main first window of the app? In the tutorial the configuration is for additional window. I can't find anywhere a place to configure main window. – Loreno Aug 15 '17 at 08:52
  • 1
    Try this: https://stackoverflow.com/questions/27227892/how-do-i-set-a-window-application-icon-in-a-application-set-up-with-caliburn-mic – Eternal21 Aug 15 '17 at 11:38

1 Answers1

1

You could create your own custom shell window by creating a custom WindowManager:

public class CustomWindowManager : WindowManager
{
    protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)
    {
        Window window = new Window();
        window.Title = "custom...";
        return window;
    }
}

...that you register in your bootstrapper:

public class HelloBootstrapper : BootstrapperBase
{
    ...

    protected override void Configure()
    {
        _container.Singleton<IWindowManager, CustomWindowManager>();
        ...
    }
}
mm8
  • 163,881
  • 10
  • 57
  • 88