Xamarin Forms - 基于选择器显示/隐藏框架

Xamarin Forms - Show / Hide Frame based off Picker

我有一个有两个值的选择器。

  1. 点击领取
  2. 运费

如何根据 select 在选择器中输入的内容显示正确的框架?

例如,如果用户 select“点击并收集”,它将显示“frameClickandCollect”。如果用户 select“Shipping”,它将显示“frameShipping”。

这是我的 XAML 代码:

<Frame x:Name="frameDeliveryOptions" BorderColor="LightGray" CornerRadius="10" HasShadow="False">
   
    <StackLayout>
      
      <Label Text="Delivery Options:" FontSize="18" TextColor="Green" FontAttributes="Bold"/>
         
      <Picker x:Name="DeliveryOptionPicker" Title="Select a delivery option" TitleColor="Black">
            
            <Picker.ItemsSource>
               
               <x:Array Type="{x:Type x:String}">
               <x:String>Click and Collect</x:String>
               <x:String>Shipping</x:String>
               </x:Array>

            </Picker.ItemsSource>
      
       </Picker>
    
     </StackLayout>

</Frame>

<Frame x:Name="frameClickandCollect" BorderColor="LightGray" CornerRadius="10" HasShadow="False">
   
    <StackLayout>
      
      <Label Text="Click and Collect Yo" FontSize="18" TextColor="Green" FontAttributes="Bold"/>
      
    </StackLayout>

</Frame>

<Frame x:Name="frameShipping" BorderColor="LightGray" CornerRadius="10" HasShadow="False">
   
    <StackLayout>
      
      <Label Text="Shipping Yo" FontSize="18" TextColor="Green" FontAttributes="Bold"/>
      
    </StackLayout>

</Frame>

您可以使用选择器 SelectedIndexChanged 事件 hide/show 您的框架,方法是使用 IsVisible= "false"/"true" XAML:

<Picker x:Name="DeliveryOptionPicker" Title="Select a delivery option" TitleColor="Black" SelectedIndexChanged="DeliveryOptionPicker_SelectedIndexChanged">

                <Picker.ItemsSource>

                    <x:Array Type="{x:Type x:String}">
                        <x:String>Click and Collect</x:String>
                        <x:String>Shipping</x:String>
                    </x:Array>

                </Picker.ItemsSource>

            </Picker>

c#:

private void DeliveryOptionPicker_SelectedIndexChanged(object sender, EventArgs e)
    {  
        //you can also use SelectedItem

        if (DeliveryOptionPicker.SelectedIndex == 1)
        {
            frameClickandCollect.IsVisible = false;
        }

    }