2015-07-21 58 views
5

不能够在Caliburn.Micro导体查看更改标题我在做,像这样:使用MahApps MetroWindow

<Controls:MetroWindow x:Class="BS.Expert.Client.App.Views.ShellView" 
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    ShowTitleBar="True" 
    Title="My Title"> 

的事情是,这是在同一时间在主定义的主干线与我控制导航通过其他窗口,所以我不能够从MetroWindow继承窗口至少试图改变视图模型标题:

public class ShellViewModel : Conductor<IScreen>.Collection.OneActive, IShell 
{ 
    public ShellViewModel() 
    { 
     #region mahApps Theme Loading 

     var theme = ThemeManager.DetectAppStyle(Application.Current); 
     var appTheme = ThemeManager.GetAppTheme(App.Configuration.Theme); 
     ThemeManager.ChangeAppStyle(Application.Current, theme.Item2, appTheme); 

     #endregion 
     //TODO: Changing Title here is not possible ((MetroWindow)this).Title = "No way"; 
     // Tudo bem na seguinte liña 
     LocalizeDictionary.Instance.Culture = new System.Globalization.CultureInfo("pt-BR"); 
     ShowPageOne(); 
    } 

    public void ShowPageOne() 
    { 
     ActivateItem(new PageOneViewModel()); 
    } 
} 

我应该如何更改名称?

回答

2

使用MVVM模式时,不应该尝试在视图模型中直接在视图上设置任何内容。而是使用数据绑定来实现这一点。

所以,你会对你的ShellViewModel属性的东西,如:

public string MyTitle 
{ 
    get { return _myTitle; } 
    set 
    { 
     _myTitle = value; 
     //Insert your property change code here (not sure of the caliburn micro version) 
    } 
} 

,并在窗口的XAML它会是这样的:

<Controls:MetroWindow 
    Title="{Binding MyTitle}" 
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
    ... 
    > 
+1

从MetroWindow继承和设置,Title属性ISN你想做什么。即使您更改了继承,也不允许您以这种方式更改视图模型中视图的标题。 ShellView和ShellViewModel只是MetroWindow的两个不同实例。如果你想设置标题实现我所描述的内容,只需将视图模型中的MyTitle属性设置为你想要的值即可。 – TylerReid

相关问题