我正在使用 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:
- Xamarin.CommunityToolkit.MauiCompat
- 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));