扩展程序处理程序问题? System.Exception: 'Handler not found for view Xamarin.CommunityToolkit.UI.Views.Expander.'

Expander Handler Issue? System.Exception: 'Handler not found for view Xamarin.CommunityToolkit.UI.Views.Expander.'

我正在使用 Visual Studio 2022 预览版 2.0 MAUI。我想在 MAUI 中使用扩展器,我已经使用了 Xamarin.CommunityToolkit.MauiCompat nuget。但是我看到异常 System.Exception: 'Handler not found for view Xamarin.CommunityToolkit.UI.Views.Expander. 我如何在 MAUI.

中解决这个问题

我的 UI 是:

<behaviors:Expander>
    <behaviors:Expander.Header>
        <HorizontalStackLayout Margin="33,-10,22,10">
            <Label FontAttributes="Bold" WidthRequest="230" VerticalOptions="Center" Text="Monday" TextColor="{DynamicResource Black}" FontSize="{DynamicResource AppFontSize_Default}"></Label>
            <Image Margin="0,0,30,0" Source="plus.png"  HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" WidthRequest="15" HeightRequest="20">
                <Image.Triggers>
                    <DataTrigger TargetType="Image" Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}" Value="True">
                        <Setter Property="Source" Value="plus.png" />
                    </DataTrigger>
                </Image.Triggers>
            </Image>
            <RadioButton  BackgroundColor="Transparent" BorderColor="{DynamicResource DefaultColor}"></RadioButton>
        </HorizontalStackLayout>
    </behaviors:Expander.Header>
    <behaviors:Expander.ContentTemplate>
        <DataTemplate>
            <Label Text="{Binding CustomerNotes}" HorizontalOptions="StartAndExpand" TextColor="Black" FontSize="14" Padding="10,0,0,0"></Label>
        </DataTemplate>
    </behaviors:Expander.ContentTemplate>
</behaviors:Expander>

我已经下载了nuget:

  1. Xamarin.CommunityToolkit.MauiCompat
  2. Xamarin.CommunityToolkit.Markup.MauiCompat

我还在我的 MauiProgram.cs 页面上添加了处理程序

// Register ALL handlers in the Xamarin Community Toolkit assembly
handlers.AddCompatibilityRenderers(typeof(Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer).Assembly);

// Register just one handler for the control you need
handlers.AddCompatibilityRenderer(typeof(Xamarin.CommunityToolkit.UI.Views.MediaElement), typeof(Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer));

我不确定 Xamarin Forms Community Toolkit 与 MAUI 的配合情况如何。 Maui Community Toolkit 仍在 pre-release,但他们计划添加 Expander Control。

您可以跟踪 Expander proposal issue on Github