C# 如何使用Caliburn.Micro 2的自定义窗口?
我想使用我自己的类来扩展窗口,以便在使用Caliburn.Micro的MVVM环境中显示对话框 我已经阅读了如何通过覆盖WindowManager中的EnsureWindow方法,或通过访问视图模型中的默认WindowManager实例并将设置字典传递给“ShowDialog”方法来自定义CM提供的窗口。尽管如此,我真正需要的是使用我自己的类,因为它包含的其他元素不能通过简单地设置一些属性提供给默认窗口 为了清楚起见,我可以为我的根视图使用默认窗口类 这可能吗?如果我的问题不合理,我很乐意进一步说明我的理由C# 如何使用Caliburn.Micro 2的自定义窗口?,c#,wpf,mvvm,caliburn.micro,C#,Wpf,Mvvm,Caliburn.micro,我想使用我自己的类来扩展窗口,以便在使用Caliburn.Micro的MVVM环境中显示对话框 我已经阅读了如何通过覆盖WindowManager中的EnsureWindow方法,或通过访问视图模型中的默认WindowManager实例并将设置字典传递给“ShowDialog”方法来自定义CM提供的窗口。尽管如此,我真正需要的是使用我自己的类,因为它包含的其他元素不能通过简单地设置一些属性提供给默认窗口 为了清楚起见,我可以为我的根视图使用默认窗口类 这可能吗?如果我的问题不合理,我很乐意进一步
提前感谢社区 根据@mvermef的建议,我做了一些研究并提出了一个解决方案。它包括重写WindowManager类的EnsureWindow方法。下面是一个例子:
protected override Window EnsureWindow(object model, object view, bool isDialog)
{
var window = view as Window;
if (window == null)
{
window = new MyCustomWindowClass
{
SizeToContent = SizeToContent.WidthAndHeight
};
// I defined a ContentControl "WindowContent" in MyCustomWindow
// class to insert the window's contents
((MyCustomWindowClass)window).WindowContent.Content = view;
window.SetValue(View.IsGeneratedProperty, true);
var owner = InferOwnerOf(window);
if (owner != null)
{
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.Owner = owner;
}
else
{
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}
else
{
var owner = InferOwnerOf(window);
if (owner != null && isDialog)
{
window.Owner = owner;
}
}
return window;
}
您不必使用内置的WindowManager。。实际上,我在我的一个应用程序中使用了Telerik RadWindow,并在需要不同功能的地方使用IWindowManager和extend。@mvermef:谢谢您的回复!只是想澄清一下,您是说您将WindowManager子类化并覆盖“ShowWindow”方法,提供您自己的自定义窗口吗?你能提供一个简单的例子吗?@mvermef:在仔细考虑了你的回答几分钟后,我继续重写WindowManager类的EnsureWindow,用我自己的扩展Window的类替换在那里创建的Window实例。这似乎奏效了。这或多或少是你用Telerik RadWindow做的吗?是的,很高兴它对你有用!