设置虚拟机继承屏幕时的Caliburn.Micro,覆盖视图中的标题字段 [英] Caliburn.Micro when setting VM to inherit Screen, overrides title field in View

查看:47
本文介绍了设置虚拟机继承屏幕时的Caliburn.Micro,覆盖视图中的标题字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的ViewModel:

If I have a ViewModel like so:

 public class ViewModel : IPropertyChangeBase, IViewModel
 {
 }

我在视图的xaml中设置的标题属性必定会正确显示。

The "Title" property I set in the xaml of the view it's bound to properly shows.

如果我让ViewModel从Screen继承,则标题中显示的是ViewModel的完整类型名称,例如 MarksProject.ViewModels.ViewModel。这会显示在窗口的标题上。

If I have the ViewModel inherit from Screen instead what shows up in the title is the complete type name of the ViewModel, like "MarksProject.ViewModels.ViewModel." This shows up on the window's title.

 //View Title property being overriden.
 public class ViewModel : Screen, IViewModel
 {
 }


推荐答案

屏幕定义了属性DisplayName,Caliburn.Micro使用该属性自动填充标题。只需在构造函数中这样设置即可:

Screen defines a property DisplayName that Caliburn.Micro uses to automatically populate headers. Just set that in the constructor like this:

public ViewModel() {
    this.DisplayName = "MyTitle";
}

您将获得标题-并在此过程中保存了一个属性;)

And you'll have your title back - and saved a Property in the process ;)

这篇关于设置虚拟机继承屏幕时的Caliburn.Micro,覆盖视图中的标题字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆