locked
How check different entries in Stacklayout.Children? RRS feed

  • Question

  • User377905 posted

    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,tabindex) 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; }

    Friday, January 25, 2019 8:04 AM

Answers

  • User89714 posted

    @Ryla

    How do you construct the structure? What does your JSON look like?

    Assuming that you dynamically created the structure from the JSON, it should be possible to update views in the structure from JSON that has the same form.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, January 27, 2019 2:22 PM

All replies

  • User377905 posted

    anyone can help?

    Friday, January 25, 2019 10:31 PM
  • User89714 posted

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

    Friday, January 25, 2019 11:11 PM
  • User377905 posted

    @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 :)

    Friday, January 25, 2019 11:50 PM
  • User89714 posted

    @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.

    Saturday, January 26, 2019 12:18 AM
  • User377905 posted

    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.

    Sunday, January 27, 2019 12:36 PM
  • User89714 posted

    @Ryla

    How do you construct the structure? What does your JSON look like?

    Assuming that you dynamically created the structure from the JSON, it should be possible to update views in the structure from JSON that has the same form.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, January 27, 2019 2:22 PM
  • User377905 posted

    @JohnHardman , you are my hero! <3

    Sunday, January 27, 2019 9:22 PM