【问题标题】:Xamarin Forms - Show / Hide Frame based off PickerXamarin Forms - 显示/隐藏基于选取器的框架
【发布时间】:2020-08-11 06:24:08
【问题描述】:

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

  1. 点击收集
  2. 运费

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

例如,如果用户选择“点击并收集”,它将显示“frameClickandCollect”。如果用户选择“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>

【问题讨论】:

    标签: c# ios xaml xamarin.forms picker


    【解决方案1】:

    您可以使用选择器 SelectedIndexChanged 事件通过 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;
            }
    
        }
    

    【讨论】:

    • 完美,就像一个魅力!感谢@ijigarsolanki 继续努力工作。
    猜你喜欢
    • 2019-09-16
    • 2020-03-31
    • 2011-05-26
    • 2022-07-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多