Hello,
Do you want to achieve this result with Context actions without any renders?
It cannot be achieved.
If you want to add the checkbox to the ListView like your screenshot; if you tab the items, checkbox will be selected without renders, you can use following listview layout.
<ListView ItemsSource="{Binding Items}" SelectionMode="Single" ItemSelected="ListView_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Label Text="{Binding Name}" VerticalOptions="CenterAndExpand" HorizontalOptions="Start"></Label>
<CheckBox IsChecked="{Binding Selected}" VerticalOptions="CenterAndExpand" HorizontalOptions="EndAndExpand"></CheckBox>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You can achieve the ListView_ItemSelected
for selecting checkbox without render in the background code.
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
Model model= e.SelectedItem as Model;
model.Selected =!model.Selected;
}
Please note, model class need to achieve INotifyPropertyChanged
for runtime change like following code.
public class Model:INotifyPropertyChanged
{
public string Name { get; set; }
private bool _selected;
public bool Selected
{
set
{
if (_selected != value)
{
_selected = value;
OnPropertyChanged("Selected");
}
}
get
{
return _selected;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Best Regards,
Leon Lu
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.