Hello,
For your needs, you could mainly divide into how to recursively update the values in an array and how to update the updated values into the control.
For how to update recursively, please refer to the following ViewModel:
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public MyViewModel()
{
Item = new UploadItem("test");
}
private UploadItem item;
public Command IconClickCommand => new Command(Update_element_recursive);
public UploadItem Item
{
get { return item; }
set
{
if (item != value)
{
item = value;
OnPropertyChanged();
}
}
}
private void Update_element_recursive()
{
update_element_recursive(this.Item.Children.Count);
}
private void update_element_recursive(int size)
{
if (size - 1 >= 0) //This represents a recursive exit condition
{
update_element_recursive(size - 1);
}
else
{
return;
}
Item.Children[size - 1].Length = 1024; //You can update the length value according to your needs
}
}
For how to make the control respond to changes in the length value, you need to add the OnPropertyChanged
event in the Model layer.
public class UploadItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public UploadItem()
{
}
public UploadItem(string name)
{
Name = name;
Children = new ObservableCollection<UploadItem>();
Children.Add(new UploadItem { Length = 123 });
Children.Add(new UploadItem { Length = 123 });
Children.Add(new UploadItem { Length = 123 });
Children.Add(new UploadItem { Length = 123 });
}
public string Name { get; set; }
public string Path { get; set; }
public string Icon { get; set; }
public IList<UploadItem> Children { get; set; }
public string IconActionListView { get; set; }
public Action IconAction { get; set; }
private void IconClicked()
{
this.IconAction?.Invoke();
}
private long length;
public long Length
{
get { return length; }
set
{
if (length != value)
{
length = value;
OnPropertyChanged();
}
}
}
public string CreatedDateTime { get; set; }
public string ModifiedDateTime { get; set; }
public string FileType { get; set; }
public override string ToString()
{
if (Icon == "file")
{
return $"Size:{(Length / 1024f) / 1024f} Mega, created at: {CreatedDateTime}, modified at: {ModifiedDateTime}, File type: {FileType} ";
}
return string.Empty;
}
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.