【问题标题】:Frame tap gesture xamarin帧点击手势 xamarin
【发布时间】:2018-11-17 02:20:20
【问题描述】:

当我点击框架时,我在框架中添加了一个点击手势,它将聚焦在我的选择器上。问题是当我点击我的框架时,选择器弹出窗口将显示,当我单击取消时,选择器弹出窗口将再次显示。我该如何解决这个问题?

 <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;
    }
 }

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    跳过点击手势,并在您的 ViewModel 中添加一个 bool 属性来控制是否启用 Picker。

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

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

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

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

    【讨论】:

    • 如何在后面的代码中做到这一点?我还没有实现 MVVM
    • @LawrenceAgulto 将 CodePickerEnabled 属性添加到您拥有 RetailerCode、DisplayText 属性的任何位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多