如何在ShellView中移动Caliburn Micro子视图?

时间:2012-05-04 00:24:46

标签: wpf mvvm caliburn.micro

我正在使用Caliburn Micro for MVVM, 所以我能够OpenViews,但不能移动它们。

我已设置WindowStyle=None,这是我的代码。

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

请帮忙。

1 个答案:

答案 0 :(得分:0)

从Caliburn Micro的WindowManager.cs中删除您的CreateWindow并添加此代码。

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();
}