我的页面中有一种奇怪的行为。
如果我集中输入条目,并输入一个字符,事件将关闭(创建新条目),我没有时间输入单词的结尾。
精度很低,在我的数据模板中只有一个条目,我有时间输入我的单词和预期的行为(如果当前条目不为空,则创建新条目)
thx寻求帮助,我不理解问题所在
xaml。页
<ListView SeparatorVisibility="None" HasUnevenRows="True" x:Name="listevisible" ItemsSource="{Binding ChirurgieList}">
<ListView.ItemTemplate>
<DataTemplate>
<local:Chirurgie>
<StackLayout x:Name="{Binding IdEntry}">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="{StaticResource Leviolet}" Padding="2" HasShadow="False" HorizontalOptions="FillAndExpand" InputTransparent="True">
<Entry Text="{Binding Chir}"
x:Name="{Binding IdEntry}"
ClassId="{Binding IdEntry}"
Keyboard="Text"
Placeholder="(vide)"
Style="{StaticResource Poursaisi}"
FontSize="Medium"
BackgroundColor="#f1f0f0"
HorizontalTextAlignment="Start"
Focused="Entry_Focusedchir"
Unfocused="Saisichir_Unfocused"/>
</Frame>
<Frame BackgroundColor="{StaticResource Leviolet}" Padding="2" HasShadow="False" WidthRequest="60" >
<Entry Text="{Binding Annee}"
x:Name="{Binding Iddate}"
ClassId="{Binding Iddate}"
Keyboard="Numeric"
Placeholder="(vide)"
Style="{StaticResource Poursaisi}"
FontSize="Medium"
BackgroundColor="#f1f0f0"
HorizontalTextAlignment="Center"
Focused="Date_focus"
Unfocused="Date_Unfocus"/>
</Frame>
<StackLayout ClassId="{Binding IdEntry}"
Orientation="Horizontal"
HorizontalOptions="End"
WidthRequest="27" >
<Image Source="{StaticResource effacement}" WidthRequest="20"/>
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Image.GestureRecognizers>
<Image/>
</StackLayout>
</StackLayout>
<BoxView HeightRequest="5"/>
</StackLayout>
</local:Chirurgie>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
和c代码
public partial class Page6 : ContentPage
{
public ObservableCollection<Chirurgie> listchir = new ObservableCollection<Chirurgie>();
public string AVsaisi;
public int compteur = 0;
public Page6()
{
InitializeComponent();
foreach (var s in (Array)Application.Current.Resources["AtcdChir"])
{ listevisible.ItemsSource = CreateItems(((Chirurgie)s).Chir, ((Chirurgie)s).Annee);}
}
//################### UNFOCUS #######################
private void Saisichir_Unfocused(object sender, FocusEventArgs e)
{
//on definit l'index de l'item
int indexCh = 25;
foreach (var item in ChirurgieList)
{
if (((Entry)sender).ClassId == item.IdEntry.ToString())
{ indexCh = ChirurgieList.IndexOf(item); }
}
//-----------------------------
// zone de saisi est vide
if (string.IsNullOrWhiteSpace(((Entry)sender).Text))
{
// elle l'était déja
if(ChirurgieList[indexCh].champsvide == true)
{ } // on ne fait rien
// elle etait pleine
else
{
//on la supprime
ChirurgieList.RemoveAt(indexCh);
}
}
// zone de saisi est pleine
else
{
// elle l'était déja
if (ChirurgieList[indexCh].champsvide == false)
{
// on ne fait rien sauf mettre a jour les valeurs
//ChirurgieList[indexCh].Chir = ((Entry)sender).Text;
((Entry)sender).Unfocus();
}
//et elle était vide
else
{
ChirurgieList[indexCh].champsvide = false;
ChirurgieList[indexCh].Chir = ((Entry)sender).Text;
listevisible.ItemsSource = CreateItems(string.Empty, string.Empty);
} }
public ObservableCollection<Chirurgie> CreateItems(string lachir, string lanee)
{
var items = ChirurgieList;
var uniqueID = compteur;
ChirurgieList.Add(new Chirurgie() {IdEntry = uniqueID, Chir = lachir, Iddate = "A" + uniqueID, Annee = lanee, champsvide=true });
compteur++;
return items;
}
public class Chirurgie
{
public string Chir { get; set; }
public int IdEntry { get; set; }
public string Iddate { get; set; }
public string Annee { get; set; }
public bool champsvide { get; set; }
}
如果我反转这两个条目,行为也会改变,因此我认为这一定与每个条目缺少唯一标识符有关,但我不确定。