【发布时间】:2021-09-24 11:41:42
【问题描述】:
说明
我在版本 4 中使用 Caliburn.Micro 并尝试从用户控件导航到另一个页面。 ShellView.xaml 有一个<ContentControl x:Name="ActiveItem" /> 元素,并且所有导航方法(如DashboardView()、GcsImportView()...)只要我在ShellView.xaml 中就可以工作。但是,如果我从用户控件(在 ContentControl 内部)调用,则不会发生任何事情。我什至没有收到错误。我可以按下按钮 thound 次而没有任何反应。我希望有人可以在这里帮助我。
更新
即使我尝试使用这些 site 中的代码,它也不起作用。在调试 ActiveItem 值将被更改。这看起来像一个错误?
ShellViewModel.cs
namespace GCS.ViewModels
{
public class ShellViewModel : Conductor<object>//, IHandle<GcsImportProgressViewModel>
{
private string _version = "v. " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string Version
{
get { return _version; }
}
public ShellViewModel(/*IEventAggregator eventAggregator*/)
{
DashboardView();
//eventAggregator.SubscribeOnUIThread(this);
}
public void DashboardView() => ActivateItemAsync(new DashboardViewModel());
public void GcsImportView() => ActivateItemAsync(IoC.Get<GcsImportViewModel>());
public void GcsExportView() => ActivateItemAsync(new GcsExportViewModel());
public void ChangeView<T>() => ActivateItemAsync(IoC.Get<T>());
//public Task HandleAsync(GcsImportProgressViewModel message, CancellationToken cancellationToken)
//{
// throw new NotImplementedException();
//}
}
}
用户控件构造函数
public GcsImportViewModel(ShellViewModel shell, IGcsRepository gcsRepository/)
{
filePath = "Bitte GCS Excel Datei auswählen";
databases = new ObservableCollection<GcsTable>(gcsRepository.GetAllTables());
selectedDatabase = databases.FirstOrDefault();
this.gcsRepository = gcsRepository;
}
用户控件改变视图的方法
public void ClickImport()
{
shell.ChangeView<GcsImportProgressViewModel>();
}
【问题讨论】:
-
shell.DashboardView();有效吗?ClickImport是否按预期调用?你如何实例化GcsImportViewModel? -
shell.DashboardView();仅当它在 shell xaml 中调用时才有效。 ClickImport 只是一个应该更改视图的按钮,我看到他跳到 ChangeView 方法的断点。但观点并没有改变。
-
你没有回答我的其他问题,尤其是关于如何实例化视图模型的问题。
-
我有一个带有 x:Name GcsImportView 的按钮。将加载 ActivateItemAsync(IoC.Get
());进入内容控件 -
所以?目前还不清楚你是如何创建
GcsImportViewModel的?
标签: c# wpf caliburn.micro