框架点击手势Xamarin

时间:2018-11-17 02:20:20

标签: xamarin xamarin.forms

当我点击框架时,我在框架中添加了轻击手势,它将集中在拾取器上。问题是,当我轻按框架时,将显示选择器弹出窗口,而当我单击“取消”时,将再次显示选择器弹出窗口。我该如何解决?

 <Frame StyleClass="fieldFrame" x:Name="OutletFrame" CornerRadius="4" BorderColor="#e8eaed" HasShadow="False">
     <Frame.GestureRecognizers>
         <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
     </Frame.GestureRecognizers>
     <local:CustomPicker x:Name="codePicker" SelectedIndexChanged="codePicker_SelectedIndexChanged" Unfocused="codePicker_Unfocused" ItemsSource="{Binding RetailerCode}" ItemDisplayBinding="{Binding DisplayText}" StyleClass="fieldForm" IsEnabled="False">
         <local:CustomPicker.FontFamily>
             <OnPlatform x:TypeArguments="x:String">
                  <On Platform="Android" Value="HelveticaNeueLTPro-Lt.otf#HelveticaNeueLTPro-Lt"/>
             </OnPlatform>
          </local:CustomPicker.FontFamily>
      </local:CustomPicker>
 </Frame>

 private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
 {
    if (!string.IsNullOrEmpty(entRetailer.Text))
    {
       codePicker.Focus();
       codePicker.IsEnabled = false;
    }
 }

1 个答案:

答案 0 :(得分:0)

跳过轻击手势,然后在ViewModel中添加一个bool属性,该属性控制是否启用Picker。

在您的XAML中,添加IsEnabled绑定:

<Picker x:Name="codePicker" 
        ItemsSource="{Binding RetailerCode}" 
        ItemDisplayBinding="{Binding DisplayText}"
        IsEnabled="{Binding CodePickerEnabled}" 
        ~~~
        />

在您的VM中,根据您的entRetailer.Text条件,添加一个true / false的bool属性:

public bool CodePickerEnabled { get { return (!String.IsNullOrEmpty(entRetailer.Text)); } }