I've got a listview with bluetooth devices that I'm connecting to. In order to pair with the devices in iOS (I'm using Xamarin.Forms) I need to be able to click the device twice in the listview (because of the pop-up saying pair for iOS) which i cannot do because that certain device has already been selected. I dont need to be pushed to another page I just want to deselect the device I just selected.
This is my listview:
<ListView x:Name="ListViewXname"
ItemsSource="{Binding Devices}"
SelectedItem="{Binding SelectedDeviceItemModel, Mode=TwoWay}"
RowHeight="90" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ContentView
Margin="10">
<Grid
HorizontalOptions="Fill"
VerticalOptions="Fill">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackLayout
Grid.Column="0"
Orientation="Vertical">
<Label
TextColor="Black"
Text="{Binding Name}"
FontSize="Large" />
<Label
Text="{Binding Id}"
TextColor="{Binding Id, Converter={StaticResource BluetoothIdToColorConverter}}" />
</StackLayout>
</Grid>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<ContentView />
</ListView.Footer>
</ListView>
This is the code I have for finding devices in my ViewModel.
private DeviceItemModel _selectedDeviceItemModel;
public DeviceItemModel SelectedDeviceItemModel
{
get => _selectedDeviceItemModel;
set
{
if (value != _selectedDeviceItemModel)
{
_selectedDeviceItemModel = value;
if (_selectedDeviceItemModel != null)
{
ConnectToDevice(_selectedDeviceItemModel.Device);
//ClearDevices();
}
SelectedDeviceItemModel = null;
}
}
}
Another option (ideally) would be to connect and get pushed to the new page when selecting pair from the pop-up.
I appreciate all the help I can get, thanks.