gpt4 book ai didi

caliburn.micro - 无法使用 MahApps MetroWindow 在 Caliburn.Micro Conductor View 中更改标题

转载 作者:行者123 更新时间:2023-12-04 15:33:11 31 4
gpt4 key购买 nike

我这样做:

<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 继承,至少尝试更改 ViewModel 中的标题:
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());
}
}

我应该如何更改标题?

最佳答案

当使用 MVVM 模式时,你永远不应该尝试像这样直接在 View 模型中设置 View 上的任何内容。而是使用数据绑定(bind)来完成此操作。

所以你会在你的 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"
...
>

关于caliburn.micro - 无法使用 MahApps MetroWindow 在 Caliburn.Micro Conductor View 中更改标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31541063/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com