Expander 不适用于 Xamarin Forms MacOS 吗?

Is Expander not available for Xamarin Forms MacOS?

我正在尝试实现 Xamarin 团队在 MacOS 上发布的新增 Expander

我正在遵循此指南:

<StackLayout x:Name="expanderLayout" IsVisible="False" BindableLayout.ItemsSource="{Binding  AllItems,Mode=TwoWay}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <Expander
                    ExpandAnimationEasing="{x:Static Easing.CubicIn}"
                    ExpandAnimationLength="500"
                    CollapseAnimationEasing="{x:Static Easing.CubicOut}"
                    CollapseAnimationLength="500">
                <Expander.Header>
                    <Frame 
                            Padding="2"
                            Margin="5"
                            HasShadow="False"
                            BorderColor="#fdeec7"
                            CornerRadius="0">

                        <StackLayout
                                HorizontalOptions="FillAndExpand"
                                VerticalOptions="FillAndExpand"
                                Orientation="Horizontal">

                            <Label 
                                    Text="{Binding unit.title}"
                                    TextColor="Black"
                                    HorizontalOptions="Start" 
                                    HorizontalTextAlignment="Start"
                                    VerticalTextAlignment="Center"
                                    VerticalOptions="CenterAndExpand">
                                <Label.FontSize>
                                    <OnIdiom x:TypeArguments="x:Double">
                                        <OnIdiom.Phone>18</OnIdiom.Phone>
                                        <OnIdiom.Tablet>36</OnIdiom.Tablet>
                                        <OnIdiom.Desktop>18</OnIdiom.Desktop>
                                    </OnIdiom>
                                </Label.FontSize>
                            </Label>

                            <StackLayout.Margin>
                                <OnIdiom x:TypeArguments="Thickness">
                                    <OnIdiom.Phone>5</OnIdiom.Phone>
                                    <OnIdiom.Tablet>8</OnIdiom.Tablet>
                                    <OnIdiom.Desktop>5</OnIdiom.Desktop>
                                </OnIdiom>
                            </StackLayout.Margin>
                            <StackLayout.Padding>
                                <OnIdiom x:TypeArguments="Thickness">
                                    <OnIdiom.Phone>5</OnIdiom.Phone>
                                    <OnIdiom.Tablet>8</OnIdiom.Tablet>
                                    <OnIdiom.Desktop>5</OnIdiom.Desktop>
                                </OnIdiom>
                            </StackLayout.Padding>
                        </StackLayout>
                    </Frame>
                </Expander.Header>
                <Expander.ContentTemplate>
                    <DataTemplate>
                        <StackLayout BindableLayout.ItemsSource="{Binding contentList,Mode=TwoWay}">
                            <BindableLayout.ItemTemplate>
                                <DataTemplate>
                                <StackLayout 
                            Orientation="Horizontal">

                                    <Label
                                    HorizontalOptions="Start"
                                    Text="{Binding title}"
                                    VerticalOptions="CenterAndExpand"     
                                    TextColor="Black">
                                        <Label.FontSize>
                                            <OnIdiom x:TypeArguments="x:Double">
                                                <OnIdiom.Phone>16</OnIdiom.Phone>
                                                <OnIdiom.Tablet>32</OnIdiom.Tablet>
                                                <OnIdiom.Desktop>16</OnIdiom.Desktop>
                                            </OnIdiom>
                                        </Label.FontSize>
                                        <Label.GestureRecognizers>
                                                        <TapGestureRecognizer
                                                            Tapped="LoadChapter"
                                                            CommandParameter="{Binding .}"
                                                            NumberOfTapsRequired="1">
                                                        </TapGestureRecognizer>
                                                    </Label.GestureRecognizers>
                                    </Label>
                                </StackLayout>
                            </DataTemplate>
                            </BindableLayout.ItemTemplate>
                           
                        </StackLayout>
                    </DataTemplate>
                </Expander.ContentTemplate>
            </Expander>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>

使用此代码导航到页面时出现异常,提示我需要调用 Xamarin.Forms.Forms.SetFlags("Expander_Experimental");,我已将其添加到 MacOS 文件夹中的 public AppDelegate() 方法中。

    public AppDelegate()
    {
        Xamarin.Forms.Forms.SetFlags("Expander_Experimental");
        Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental");

        var style = NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.Titled | NSWindowStyle.FullSizeContentView;
        var frame = NSScreen.MainScreen.Frame;
        var rect = NSWindow.FrameRectFor(frame, style);
        _window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
        _window.MinSize = new CoreGraphics.CGSize(400, 300);
        _window.TitlebarAppearsTransparent = true;
        _window.MovableByWindowBackground = true;
        _window.AccessibilityMinimized = false;
    }

扩展器是否不支持 MacOS,还是我错过了关键步骤?

我也试过在DidFinishLaunching方法中添加它,但没有区别。

    public override void DidFinishLaunching(NSNotification notification)
    {   
        Xamarin.Forms.Forms.SetFlags("Expander_Experimental");
        Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental");

        Forms.Init();
        CachedImageRenderer.Init();
    ...

我在测试这个新组件时几乎 运行 亲自参与其中!如 Xamarin.Forms experimental flags 页面所述:

Never call the SetFlags method more than once, as subsequent calls will overwrite the result of previous calls.

所以代替:

Xamarin.Forms.Forms.SetFlags("Expander_Experimental");
Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental"); // This call overwrites the `Expander_Experimental` flag set just above

调用一次,但有两个标志:

Xamarin.Forms.Forms.SetFlags(new string[] { "Expander_Experimental", "CarouselView_Experimental" } );