我们不能在使用ViewModel
7的.NET毛伊岛应用程序中使用.NET for AppShell
吗?
我在使用.NET 6的.NET毛伊岛上成功地做到了这一点,但现在它似乎不起作用。
下面是我使用ViewModel
for AppShell
所做的工作。
在我的应用程序的Flyout
中有两个关键功能:第一,我在FlyoutHeader
和FlyoutFooter
中显示用户的图像,我有一个注销图标,允许用户注销应用程序。
我的解决方案是将AppShell
绑定到自己的ViewModel
,即AppShellViewModel
,并为用户的图像URL使用一个属性。我还添加了一个函数,当用户在FlyoutFooter
中点击FlyoutFooter
图标时调用该函数。
当我的.NET毛伊岛应用程序在.NET 6上运行时,这是很好的,但是自从我切换到.NET 7之后,我既看不到用户的图像,也无法登录。我在SignOut()
函数的AppShellViewModel
中放置了一个断点,但是点击注销图标似乎没有击中SignOut()
方法。
这是AppShellViewModel
public partial class AppShellViewModel : BaseViewModel
{
public AppShellViewModel()
{
// Once user logs in, we get the avatar URL thru MessagingCenter
MessagingCenter.Subscribe<string>(this, "avatarUrlUpdated", (url) =>
{
avatarUrl = url;
}
}
[ObservableProperty]
string avatarUrl;
[RelayCommand]
async Task SingOut()
{
// Handle user sign out
}
}
然后我们将其绑定到AppShell
中,代码在后面:
public partial class AppShell : Shell
{
AppShellViewModel _vm;
public AppShell(AppShellViewModel vm)
{
InitializeComponent();
_vm = vm;
BindingContext = _vm;
}
}
同样,当应用程序以.NET 6为目标时,这段代码运行良好。现在,无论是阿凡达更新还是我都不能点击登录。知道这是怎么回事吗?
顺便说一句,在MauiProgram.cs
中,我确实将AppShell
和AppShellViewModel
添加到DI容器中,即
services.AddSingleton<AppShell>();
services.AddSingleton<AppShellViewModel>();
发布于 2022-11-21 01:04:31
你使用CommunityToolkit.Mvvm nuget软件包了吗?如果是这样,CommunityToolkit.Mvvm nuget包装目前不支持.NET 7。
https://stackoverflow.com/questions/74495536
复制相似问题