XAML 在我选择一个项目并点击屏幕上的任何其他位置后,.Net Maui Picker不断出现

sqougxex  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(170)

下面是代码,它是一个简单的选择器,在最新版本的Android上运行良好,但在7.1上它会出错

<?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"
             Shell.NavBarIsVisible="false"
             x:Class="Views.Picker">
    <ContentPage.Content >
        <VerticalStackLayout Margin="25, 15">
            <Label Text="Device Picker" HorizontalTextAlignment="Center"/>

            <Grid>
                <Picker Grid.Column="0" SelectedItem="Dev" Margin="0,15,0,15" WidthRequest="200" HeightRequest="40">
                    <Picker.Items>
                        <x:String>Dev</x:String>
                        <x:String>Testing</x:String>
                        <x:String>Training</x:String>
                        <x:String>Production</x:String>
                    </Picker.Items>
                </Picker>

                <Image Source="small_down_arrow.png" 
                       Grid.Column="1"
                       x:Name="devicePicker"
                       WidthRequest="15" 
                       HeightRequest="15" 
                       HorizontalOptions="End"
                       Margin="0,0,6,0"
                   >
                </Image>
            </Grid>
        </VerticalStackLayout>
    </ContentPage.Content>
</ContentPage>

下面是正在发生的事情的一个例子。

我能找到的最接近的问题是这个:
Issue with Android MAUI .net picker - picker keeps reappearing
但在这种情况下,他通过将选择器放置在CollectionView中来解决它。正如你在上面的代码中看到的那样,这对我来说不起作用。

bejyjqdl

bejyjqdl1#

假设Picker占用了屏幕的其他区域,在点击屏幕上的冗余空间后,它会继续出现。要解决潜在的问题,您可以尝试设置PickerWidthRequestHeightRequest,如下所示:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             Shell.NavBarIsVisible="false"
             x:Class="Views.Picker">
    <ContentPage.Content >
        <VerticalStackLayout Margin="25, 15">
            <Label Text="Device Picker" HorizontalTextAlignment="Center"/>

            <Grid>
                <Picker Grid.Column="0" SelectedItem="Dev" Margin="0,15,0,15" WidthRequest="70" HeightRequest="40" BackgroundColor="Red">
                    <Picker.Items>
                        <x:String>Dev</x:String>
                        <x:String>Testing</x:String>
                        <x:String>Training</x:String>
                        <x:String>Production</x:String>
                    </Picker.Items>
                </Picker>

                <Image Source="small_down_arrow.png" 
                       Grid.Column="1"
                       x:Name="devicePicker"
                       WidthRequest="15" 
                       HeightRequest="15" 
                       HorizontalOptions="End"
                       Margin="0,0,6,0"
                   >
                </Image>
            </Grid>
        </VerticalStackLayout>
    </ContentPage.Content>
</ContentPage>

相关问题