Forum Xamarin.Forms

How check different entries in Stacklayout.Children?

RylaRyla Member ✭✭
edited January 2019 in Xamarin.Forms

Hi everyone, good work :)
I want only one Entrq.Text changed. My problem is that they all change at the same time
I check entries in my Stacklayout.Children. Try more way(ClassId,Id,tabındex) couldn't solve the problem.

My problem Video =

https://drive.google.com/file/d/1T6fts0gPxusFTDLWpw3UjurNNCEOYAVI/view?usp=sharing

## My Code =
public StackLayout Fill_Fields(string DataJson, StackLayout Design) { StackLayout res = Design; if(DataJson != null) { dynamic Data = JsonConvert.DeserializeObject(DataJson); foreach (var item in res.Children) { if (item.GetType() == typeof(Picker)) { Picker picker = (Picker)item; picker.SelectedItem = null; picker.SelectedItem = Data[picker.ClassId].ToString(); } else if (item.GetType() == typeof(Entry)) { Entry entry = (Entry)item; entry.Text = Data[entry.ClassId].ToString(); entry.SetDynamicResource(StyleProperty, "frmDesignerEntry"); } else if (item.GetType() == typeof(AccountEntry)) { AccountEntry accountEntry = (AccountEntry)item; if (DropdownSelectedItems.Title != null) { accountEntry.PropertyChanging += (object sender, PropertyChangingEventArgs e) => { var m = accountEntry.ClassId.ToString(); var s = accountEntry.Text; accountEntry.Text = DropdownSelectedItems.Title; }; } else { accountEntry.Text = Data[accountEntry.ClassId].ToString(); } } else if (item.GetType() == typeof(DatePicker)) { DatePicker datePicker = (DatePicker)item; DateTime date = new DateTime(); date = Convert.ToDateTime(Data[datePicker.ClassId].ToString()); datePicker.Date = date; datePicker.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)); } else if (item.GetType() == typeof(Editor)) { Editor editor = (Editor)item; editor.Text = Data[editor.ClassId].ToString(); } } } res.Children.Add(Form_Buttons(res, DataJson)); return res; }

Tagged:

Best Answer

Answers

  • RylaRyla Member ✭✭

    anyone can help?

  • JohnHardmanJohnHardman GBUniversity mod

    @Ryla said:
    anyone can help?

    You're more likely to get responses if you format your code so that it is readable.

    Your foreach loop

                     foreach (var item in res.Children)
    

    iterates through every child of the StackLayout. Any child that is of type Entry will have its Text changed

                         else if (item.GetType() == typeof(Entry))
                         {
                             Entry entry = (Entry)item;
                             entry.Text = Data[entry.ClassId].ToString();
                             entry.SetDynamicResource(StyleProperty, "frmDesignerEntry");
                         }
    

    You haven't said what you want to happen. If AccountEntry is derived from Entry (your code does not show that) and you want AccountEntry to behave differently, test for typeof(AccountEntry) before typeof(Entry).

             public StackLayout Fill_Fields(string DataJson, StackLayout Design)
             {
                 StackLayout res = Design;
                 if(DataJson != null) 
                 {
                     dynamic Data = JsonConvert.DeserializeObject(DataJson);
                     foreach (var item in res.Children)
                     {
                         if (item.GetType() == typeof(Picker))
                         {
                             Picker picker = (Picker)item;
                             picker.SelectedItem = null;
                             picker.SelectedItem = Data[picker.ClassId].ToString();
                         }
                         else if (item.GetType() == typeof(Entry))
                         {
                             Entry entry = (Entry)item;
                             entry.Text = Data[entry.ClassId].ToString();
                             entry.SetDynamicResource(StyleProperty, "frmDesignerEntry");
                         }
                         else if (item.GetType() == typeof(AccountEntry))
                         {
                             AccountEntry accountEntry = (AccountEntry)item;
                             if (DropdownSelectedItems.Title != null)
                             {
                                 accountEntry.PropertyChanging += (object sender, PropertyChangingEventArgs e) =>
                                   {
                                       var m = accountEntry.ClassId.ToString();
                                       var s = accountEntry.Text;
                                               accountEntry.Text = DropdownSelectedItems.Title;
                                   };
                             }
                             else
                             {
                                 accountEntry.Text = Data[accountEntry.ClassId].ToString();
                            }
                         }
                         else if (item.GetType() == typeof(DatePicker))
                         {
                             DatePicker datePicker = (DatePicker)item;
                             DateTime date = new DateTime();
                             date = Convert.ToDateTime(Data[datePicker.ClassId].ToString());
                             datePicker.Date = date;
                             datePicker.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
                         }
                         else if (item.GetType() == typeof(Editor))
                         {
                             Editor editor = (Editor)item;
                             editor.Text = Data[editor.ClassId].ToString();
                         }
                     }
                 }
                 res.Children.Add(Form_Buttons(res, DataJson));
                 return res;
             }
    
  • RylaRyla Member ✭✭

    @JohnHardman Firstly, Thank you for your answer.
    I tried to edit it, but I didn't get a regular look.Can you share how?

    You watch my video? This AccountEntry a Entry renderer so Image with Entry.
    I want to give two different values at the same time. https://drive.google.com/file/d/1T6fts0gPxusFTDLWpw3UjurNNCEOYAVI/view?usp=sharing
    When select a value, all AccountEntries on this page Text same value.
    I want when click a AccountEntry and update Text, only clicked entry value update, not others.

    Good Work :)

  • JohnHardmanJohnHardman GBUniversity mod

    @Ryla said:
    I tried to edit it, but I didn't get a regular look.Can you share how?

    You need to end each line with CR/LF (carriage return/linefeed).
    I am guessing that you are working on a Mac?

    @Ryla said:
    I want when click a AccountEntry and update Text, only clicked entry value update, not others

    As per my previous post, your foreach and check for typeof(Entry) are causing the problem. If you want to click on an AccountEntry and subsequently have just that item update, then you should not use the foreach loop. Instead, you would need to remember which AccountEntry had been tapped (store a reference to it when the AccountEntry is tapped) and then only update the AccountEntry that you keep the reference to when you then pick the text from the grid beneath.

  • RylaRyla Member ✭✭

    Hi @JohnHardman good work :) ,
    Thanks for information. Yes working with Mac.

    Sorry. I tried other ways.

    I'am Catching which one is clicked now.
    But how to find without loop Entries?
    because I did not use XAML.
    This dynamic structure and I only C# used.

  • RylaRyla Member ✭✭

    @JohnHardman , you are my hero! <3

Sign In or Register to comment.