我有一个表单,其中有许多标签和文本字段。因此,我通过单击键盘上的选项卡按钮在文本字段或条目中进行导航。普通条目将注意力集中在单击上,而自定义条目AutoSuggestBoxView则需要在选项卡上单击两次才能获得焦点。我不知道为什么要面对这个问题。我已将tabindex设置为0和-1,但仍然无法正常工作。这是我的xaml代码
<CtrlUC:UCCurrentLocation Grid.Row="0" HeightRequest="32" Grid.Column="0" Latitude="{Binding FieldsData.fromlatitude.Value,Mode=TwoWay}" Longitude="{Binding FieldsData.fromlongitude.Value,Mode=TwoWay}" Grid.RowSpan="2" Grid.ColumnSpan="2" HorizontalOptions="Fill" VerticalOptions="Fill" WidthRequest="400" Title="Location" LatitudeTitle="Latitude" LongitudeTitle="Longitude" ButtonText="Location" IsEditable="False" IsVisible="{Binding Path=FieldsData.FromLocationControl.IsVisible, Mode=TwoWay}" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromState" Grid.Row="1" Grid.Column="2" TabIndex="-1" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromState.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromState.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromStateSelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromstatePropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromstatename.Value, Mode=TwoWay}" Placeholder="Enter State" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromState.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="3" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromstatecode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromStateCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCity" Grid.Row="1" Grid.Column="4" TabIndex="" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromCity.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromCity.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCitySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcityPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcityname.Value, Mode=TwoWay}" Placeholder="Enter City" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromCity.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="5" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcitycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCityCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCounty" Grid.Row="1" Grid.Column="6" TabIndex="0" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromcounty.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromcounty.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCountySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcountyPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcountyname.Value, Mode=TwoWay}" Placeholder="Enter County" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromcounty.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="7" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcountycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCountyCodeValue.IsVisible, Mode=TwoWay}" />
因此,如您在代码中所见,像CCEntry这样的普通条目仅需单击一下标签即可。但是自定义条目AutoSuggestBoxView会在选项卡上单击两次以获取焦点。我不知道如何解决此问题。有什么建议吗?
答案 0 :(得分:0)
只有一种方法可以避免在xamarin.forms中多次单击,因为您必须使用如下所示的布尔标志
public class MyPage : ContentPage
{
public isClicked = false;
public MyPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
isClicked = false;
}
private void ItemTapped(object sender, System.EventArgs e)
{
if(isClicked)
return;
isClicked = true;
//Do your work here
}
}
我正在使用这种方式来避免多次点击。