Search code examples
wpfmvvmcaliburn.micro

How to Move Caliburn Micro Child View in ShellView?


I am using Caliburn Micro for MVVM, so i am able to OpenViews, but not able to Move them.

I have set WindowStyle=None and here is my code.

private void OpenView(object ViewModel)
{
    windowManager.ShowWindow(ViewModel,
    settings: new Dictionary<string, object>
    {
        {"Background",Brushes.Transparent},
        { "WindowStyle", WindowStyle.None},
        { "ShowInTaskbar", false},  
        {"AllowsTransparency",true}
    });
}

Please help.


Solution

  • Remove your CreateWindow from WindowManager.cs of Caliburn Micro and add this code.

    protected virtual Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings) {
        var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog);
        ViewModelBinder.Bind(rootModel, view, context);
    
        var haveDisplayName = rootModel as IHaveDisplayName;
        if (haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty)) {
            var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay };
            view.SetBinding(Window.TitleProperty, binding);
        }
    
    
        view.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Window_MouseDown);
        ApplySettings(view, settings);
    
        new WindowConductor(rootModel, view);
    
        return view;
    }
    
    void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        var view = sender as Window;
        view.DragMove();
    }