2017-12-14 21 views
0

내 페이지에 이상한 동작이 있습니다.Xamarin.forms : 한 문자를 입력 한 후 초점이 맞지 않습니다.

내 항목에 초점을 맞추고 하나의 char을 입력하면 이벤트가 꺼지고 (새 항목 만들기) 단어의 끝을 입력 할 시간이 없습니다.

작은 정밀도를 내 DataTemplate을 단지 하나 개의 항목으로, 내가 도움을

THX (현재 항목이 비어 있지 않은 경우 새 항목을 만들) 내 말과 예상되는 동작의 작업을 입력 할 수있는 시간이, 내가 돈 ' t 문제를

xaml.page

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

두 엔트리를 뒤집 으면 동작이 바뀌므로 각 엔트리에 대해 고유 한 식별자가없는 연결이 있어야한다고 생각합니다. 확실하지 않습니다.

답변

0

괜찮습니다. 내 페이지가 바뀝니다. 그리드 그에게

private void champcomplet(object sender, EventArgs e)  
    { 
     ((EntryChir)sender).Unfocus(); 

     testeur.Text = ((EntryChir)sender).ClassId.ToString(); 

     //on definit l'index de l'item 
     int indexCh = 25; 
     foreach (var item in Conteneur) 
     {     
      if (((EntryChir)sender).ClassId == item.Num.ToString()) // tester Entrychir partout 
      { indexCh = Conteneur.IndexOf(item); } 
     } 

     //----------------------------- 
     // zone de saisi est vide 
     if (string.IsNullOrWhiteSpace(((EntryChir)sender).Text)) 
     { 
      // elle l'était déja 
      if(Conteneur[indexCh].Itemchir.Champsvide == true) 
      { } // on ne fait rien 

      // elle etait pleine 
      else 
      { 
       //on la supprime 
       Conteneur.RemoveAt(indexCh);     
      } 
     } 

     // zone de saisi est pleine 
     else 
     { 
      // elle l'était déja 
      if (Conteneur[indexCh].Itemchir.Champsvide == false) 
      {      
       // on ne fait rien sauf mettre a jour les valeurs 
       //ChirurgieList[indexCh].Chir = ((Entry)sender).Text; 
      } 

      //et elle était vide 
      else 
      { 
       Conteneur[indexCh].Itemchir.Champsvide = false; 
       Conteneur[indexCh].Itemchir.Chir = ((Entry)sender).Text; 

       listevisible.ItemsSource = Creaconteneur("", ""); 
       //listevisible.ItemsSource = CreateItems(string.Empty, string.Empty); 

      } 
     }   
    } 
뒤에 솔루션 :

<ListView SeparatorVisibility="None" HasUnevenRows="True" x:Name="listevisible"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <ViewCell> 
          <Grid ColumnSpacing="2"> 
           <Grid.RowDefinitions> 
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="5"/> 
           </Grid.RowDefinitions> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="60" /> 
            <ColumnDefinition Width="*"/> 
            <ColumnDefinition Width="30" /> 
           </Grid.ColumnDefinitions> 

           <Frame BackgroundColor="{StaticResource Leviolet}" Padding="2" HasShadow="False" WidthRequest="60" Grid.Column="0" Grid.Row="0" > 
            <local:EntryAnn Text="{Binding Itemanee.Lannee}"             
               ClassId="{Binding Itemanee.Iddate}" 
               Keyboard="Numeric"             
               Placeholder="(vide)"       
               Style="{StaticResource Poursaisi}"       
               FontSize="Medium"       
               BackgroundColor="#f1f0f0"       
               HorizontalTextAlignment="Center"> 
            </local:EntryAnn> 
           </Frame> 

           <Frame BackgroundColor="{StaticResource Leviolet}" Padding="2" HasShadow="False" HorizontalOptions="FillAndExpand" Grid.Column="1" Grid.Row="0"> 
            <local:EntryChir Text="{Binding Itemchir.Chir}"             
                ClassId="{Binding Itemchir.IdEntry}" 
                Keyboard="Text"             
                Placeholder="(vide)"       
                Style="{StaticResource Poursaisi}"       
                FontSize="Medium"       
                BackgroundColor="#f1f0f0"       
                HorizontalTextAlignment="Start" 
                Completed="champcomplet" 
                Unfocused="Saisichir_Unfocused"/> 
           </Frame> 

           <StackLayout ClassId="{Binding Num}" Grid.Column="2" Grid.Row="0" Orientation="Horizontal" HorizontalOptions="End" WidthRequest="27" > 
            <Image Source="{StaticResource effacement}" WidthRequest="20"/> 
            <Image.GestureRecognizers> 
             <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/> 
            </Image.GestureRecognizers> 
            <Image/> 
           </StackLayout> 

           <BoxView HeightRequest="5" Grid.Column="0" Grid.Row="1"/> 
           <BoxView HeightRequest="5" Grid.Column="1" Grid.Row="1"/> 
           <BoxView HeightRequest="5" Grid.Column="2" Grid.Row="1"/> 

          </Grid> 
          </ViewCell> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 

및 코드