3

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

我的用户界面是:

<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));
4

1 回答 1

1

我不确定 Xamarin Forms Community Toolkit 与 MAUI 的配合情况如何。Maui Community Toolkit仍处于预发布阶段,但他们计划添加 Expander Control。

您可以在 Github 上跟踪Expander 提案问题

于 2022-02-09T07:13:53.420 回答