8 wpf window title caliburn.micro
我在WPF Window-它的shell的Title属性上的shell视图模型类中有绑定属性的简单问题.
我的shell视图如下所示:
<Window x:Class="Spirit.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding Path=Title}" >
<Grid>
<ContentControl x:Name="ActiveItem" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
shell视图模型类:
[Export(typeof(IShellViewModel))]
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive, IShellViewModel
{
private string _title;
public string Title
{
get { return _title; }
set
{
_title = value;
NotifyOfPropertyChange(()=>Title);
}
}
public ShellViewModel()
{
Title = "Spirit";
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行app的shell视图标题(WPF窗口)是Namespace.ShellViewModelClass,则在shell视图模型类中没有属性Title的值.
如果我在shell视图中激活某个屏幕,则窗口的Title属性是Namespace.ViewModelClass.
如何删除此行为?谢谢你的建议.
小智 20
由于IScreen是使用IHaveDisplayName定义的,并且CM框架的Screen类具有DisplayName属性,因此您只需要在ShellViewModel中设置该属性,如下所示:
public ShellViewModel()
{
base.DisplayName = "Spirit";
}
Run Code Online (Sandbox Code Playgroud)