Recently started studying C#, making a project using AvaloniaUI, ReactiveUI and a MVVM pattern.
The essence of the problem is as follows: there is an AvaloniaList(observable collection), a ListBox is bound to it by binding.
MainWindow.axaml:
<ListBox Items="{Binding Devices}"
SelectedItem="{Binding SelectedDevice}"
SelectionMode="Single, Toggle">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<TextBlock FontSize="18" Text="{Binding name}" />
<TextBlock Text="{Binding state}" />
<TextBlock Text="{Binding ip}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ViewModels:
private AvaloniaList<Device>? devices;
public AvaloniaList<Device> Devices
{
get => devices;
set
{
devices = value;
this.RaiseAndSetIfChanged(ref devices, value);
}
}
How can I make a ListBox update when the field of a certain AvaloniaList element changes?
So far I see only one option: to clear and re-fill the collection, but I would like to avoid this.