最近,我开始研究MVVM,在其中我正在研究Caliburn.Micro框架。不幸的是,我只能看到非常老的内容,框架文档已经过时了。我使用的是杯标4.0.173,它不再有被ActivateItemAsync取代的ActivateItemAsync方法,请按照下面的代码: ShellViewModel.cs。
ShellViewModel.cs
public async void LoadPageOne()
{
await ActivateItemAsync(new FirstChildViewModel(), CancellationToken.None);
}
public async void LoadPageTwo()
{
await ActivateItemAsync(new SecondChildViewModel(), CancellationToken.None);
}ShellView.Xaml
<!-- Row 5 -->
<Button x:Name="LoadPageOne" Grid.Row="5" Grid.Column="1"> Load First Page</Button>
<Button x:Name="LoadPageTwo" Grid.Row="5" Grid.Column="2"> Load Second Page</Button>
<!-- Row 6 -->
<ContentControl Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="5" x:Name="ActiveItem"/>在视频中,他使用的是dotnet框架4.6和3.2中的杯本,而我使用的是dotnet 6。即使添加了我想要找到的所有内容,即使是在github上,用户控制屏幕也不会改变。谁能告诉我我把它放哪儿了吗?我是一个初级程序员,我想了解这个问题,而不是把所有的东西都改到以前的版本。
发布于 2022-10-21 20:45:05
我试过了,效果很好。
如果您想使用内置于IoC中并希望在视图模型之间添加消息传递,则可以签出我的样本项目。
ViewModels:
using Caliburn.Micro;
using System.Threading.Tasks;
namespace CaliburnMicroDemo.ViewModels;
public class ShellViewModel : Conductor<IScreen>
{
public async Task LoadPageOneAsync()
{
await ActivateItemAsync(new FirstChildViewModel());
}
public async Task LoadPageTwoAsync()
{
await ActivateItemAsync(new SecondChildViewModel());
}
}
public class FirstChildViewModel : Screen
{
}
public class SecondChildViewModel : Screen
{
}ShellView.xaml:
<Window x:Class="CaliburnMicroDemo.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Shell Window" Height="450" Width="800">
<DockPanel>
<Button x:Name="LoadPageOneAsync" Content="Load First Page" DockPanel.Dock="Top"/>
<Button x:Name="LoadPageTwoAsync" Content="Load Second Page" DockPanel.Dock="Top"/>
<ContentControl x:Name="ActiveItem" DockPanel.Dock="Bottom"/>
</DockPanel>
</Window>FirstChildView.xaml:
<UserControl x:Class="CaliburnMicroDemo.Views.FirstChildView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="1"/>
</Grid>
</UserControl>SecondChildView.xaml:
<UserControl x:Class="CaliburnMicroDemo.Views.SecondChildView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="2"/>
</Grid>
</UserControl>https://stackoverflow.com/questions/73506270
复制相似问题