求助:.NET MAUI CommunityToolkit Popup V2.0无法正常运行
CommunityToolkit.Maui v12.0.0 Popup V2.0 使用问题
将应用更新至CommunityToolkit.Maui v12.0.0后,新版Popup功能无法正常工作。已安装要求的.NET SDK 9.0.301,为排查问题创建了一个匹配文档示例的小型项目,但遇到编译错误。
项目代码
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyProject" x:Class="MyProject.MainPage"> <ContentPage.BindingContext> <local:MainViewModel /> </ContentPage.BindingContext> <ScrollView> <VerticalStackLayout Padding="30,0" Spacing="25"> <Image Source="dotnet_bot.png" HeightRequest="185" Aspect="AspectFit" SemanticProperties.Description="dot net bot in a hovercraft number nine" /> <Label Text="Hello, World!" Style="{StaticResource Headline}" SemanticProperties.HeadingLevel="Level1" /> <Label Text="Welcome to .NET Multi-platform App UI" Style="{StaticResource SubHeadline}" SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" /> <Button x:Name="CounterBtn" Text="Click me" SemanticProperties.Hint="Counts the number of times you click" Command="{Binding CounterClickedCommand}" HorizontalOptions="Fill" /> </VerticalStackLayout> </ScrollView> </ContentPage>
MainViewModel.cs
using CommunityToolkit.Maui.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace MyProject { public partial class MainViewModel : ObservableObject { public MainViewModel() { } [RelayCommand] public async Task ButtonClicked() { var popup = new SimplePopup(); // Ensure PopupOptions and ShowPopupAsync are correctly referenced await this.ShowPopupAsync(popup,PopupOptions.Empty); } } }
SimplePopup.xaml
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyProject.SimplePopup" Padding="10"> <Label Text="This is a very important message!" /> </ContentView>
MauiProgram.cs
using CommunityToolkit.Maui; using Microsoft.Extensions.Logging; namespace MyProject { public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .UseMauiCommunityToolkit() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); #if DEBUG builder.Logging.AddDebug(); #endif return builder.Build(); } } }
遇到的错误
using CommunityToolkit.Maui.Views;显示为灰色(未被实际使用)await this.ShowPopupAsync(popup,PopupOptions.Empty);行出现红色下划线,错误提示:
'MainViewModel' does not contain a definition for 'ShowPopupAsync' and no accessible extension method 'ShowPopupAsync' accepting a first argument of type 'MainViewModel' could be found (are you missing a using directive or an assembly reference?)
请问有人成功使用Popup V2.0了吗?如果有的话,请指出我的示例中存在的问题。
内容的提问来源于stack exchange,提问作者user3017691
相关产品推荐
相关产品推荐

