Inside the DataTemplate
of a CollectionView I have modifiable UI-Elements (for example Checkbox or Entry) bound to the underlying objects properties. Whenever the user modifies an UI-Element inside the CollectionView, I want to know which object has been modified.
My first approach was to add an optional value to the class definition public bool? modified { get; set; }
and update this property in the ItemSelection-Callback. Yet, the Item-Selection event will not get triggered when the user clicks on an UI-Element inside the CollectionView.
What would be a better approach to achieve this goal?
<CollectionView Margin="0,5"
ItemsSource="{Binding digitalInputs}"
SelectionMode="Single"
SelectionChanged="OnSelectDigitalInput">
[...]
<Entry Text="{Binding pName}"/>
[...]
</CollectionView>
public class DigitalOutput
{
public string pName { get; set; }
public bool? modified { get; set; }
[...]
}
public partial class DigitalView : ContentPage
{
public ObservableCollection<DigitalOutput> digitalOutputs { get; }
[...]
void OnSelectDigitalOutput(System.Object sender, Microsoft.Maui.Controls.SelectionChangedEventArgs e)
{
(e.CurrentSelection.FirstOrDefault() as DigitalOutput).modified = true;
}
}