Xamarin Forms - Issue with Swipe to Delete on iOS - xamarin.forms

So I implemented swipe to delete functionality for iOS and long tap to delete for Android, everything works fine except - on iOS after swiping a cell and clicking delete button I am displaying Alert to confirm if user wants to delete item# XYZ, when alerts pops up another cell gets swiped.
Any suggestions how to fix it?
XAML:
<ViewCell.ContextActions>
MenuItem CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference Name=ListPage}}"
</ViewCell.ContextActions>
ViewModel (when delete command is called):
string Msg = string.Format("Delete item {0}?", selectedItem.ItemNumber);
var answer = await App.Current.MainPage.DisplayAlert(App.ResourceContainer.GetString("Confirmation_Message"),
Msg,
App.ResourceContainer.GetString("Yes"),
App.ResourceContainer.GetString("No"));

Related

CollecionView RemainingItemThresholdReached is not firing when Tabbed Pages are initialized in Xamarin iOS

I am stuck with this annoying problem in iOS(works perfectly fine in Android) and I can't seem to find a solution at all. Could someone please help me? Thanks.
I have tabbed pages in which I have a Message Tab which consists of a collection view which shows the user messages. When the app starts I download about 5 messages and then wait for the remainingitemthresholdreached to fire so I can go ahead and fetch more data but unfortunately, it doesn't fire and I am stuck with the initial 5 messages.
XAML
<CollectionView Grid.Row="1" ItemsSource="{Binding AllMessages, Mode=TwoWay}" x:Name="myMessagesCV" SelectionMode="Single" SelectionChanged="MyMessagesCV_SelectionChanged" RemainingItemsThresholdReached="MyMessagesCV_RemainingItemsThresholdReached" RemainingItemsThreshold="5">
<CollectionView.ItemTemplate>
<DataTemplate>
// Some Code here
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Code Behind
private void MyMessagesCV_RemainingItemsThresholdReached(object sender, EventArgs e)
{
if (IsBusy)
return;
IsBusy = true;
if (!LoadedAllMyMessages)
{
GetMyMessages();
}
if (LoadedAllMyMessages)
{
myMessagesCV.RemainingItemsThreshold = -1;
}
}
Please someone save me. Cheers guys!
The RemainingItemsThresholdReached could be triggered with enough items.
You could check it in IncrementalLoadingPage of Scrolling. Or you could use the RemainingItemsThresholdReachedCommand
Here is the example for yoru reference. https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/CollectionViewDemos

Can't select same item twice on CollectionView

I use a CollectionView control to display a list of files, if users click an item a popup appears displaying information about the file and a button to download it, the problem is that I use the SelectionChanged method of the CollectionView to run this action, but if users close the popup and click again on the same item nothing happens. Back when we use ListView control, the ItemTapped event runs every time the users click the same item, but i need to changed to CollectionView because later we'll change the file item from a single row to multiple columns (2 or 3).
It is possible to make the users click on the same item multiple times with CollectionView control ?
P.D: also try to set the SelectedItem to null but the app crashes if the users select again the same item.
It works for me when i set SelectedItem to null.What else did you do when you set selectitem?
below is my simple sample,i use DisplayAlert instead of popup.
the xaml :
<CollectionView x:Name="collection" SelectionChanged="CollectionView_SelectionChanged" SelectionMode="Single" >
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
<x:String>Squirrel Monkey</x:String>
<x:String>Golden Lion Tamarin</x:String>
<x:String>Howler Monkey</x:String>
<x:String>Japanese Macaque</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
in page xaml.cs:
private async void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (collection.SelectedItem != null)
{
await DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");
collection.SelectedItem = null;
}
}
the effect is like below:

Xamarin.Forms Caliburn.Micro button click event doen't fire

I'm new to Xamarin.Forms and try to use Caliburn Micro like i did with WPF.
But my button click doesn't fire ?
My mainview does show on my connected phone, so far so good!
I know this is very basic but i can't get it work
<Button x:Name="Connect" Grid.Row="1" Text="Connect" TextColor="Gainsboro" BackgroundColor="green" />
In my view model :
public void Connect()
{
IntroLabel = "Caliburn.Micro!";
}
Kind Regards
Johan

MaterialDesignXaml dialog from Caliburn.Micro View Model

I'm having a problem with showing Dialogs from a View Model. The problem is that the "underlying content is not dimmed and disabled" as the documentation says it should be. If I click on the underlying view the button in the dialog wired to the closed command is sometimes disabled and the user is not able to click it.
I defined the DialogHost in my MainView like this (also tried it in the ShellView):
<materialDesign:DialogHost
HorizontalAlignment="Center"
VerticalAlignment="Center"
CloseOnClickAway="True" />
From my MainViewModel I show the dialog like this:
Dim errView As New ErrorView
Dim res = Await DialogHost.Show(errView)
I wired up the close command on a button in the ErrorView dialog like this:
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
You problem is with the definition of DialogHost; you have it as an empty element.
The DialogHost is a ContentControl. Everything inside is what will become dimmed. So you define it at the root of your main Window/Page XAML, a bit more like:
<materialDesign:DialogHost CloseOnClickAway="True">
<StackPanel>
<TextBlock>Hello World</TextBlock>
<TextBlock>This is the main content of my application</TextBlock>
</StackPanel>
</materialDesign:DialogHost>

ListBox not updating in Windows Phone 7

I have a weird error which I can't figure out.
I am creating a Windows Phone 7 app where I create PivotItems on the fly that contains a ListBox.
Heres the code -
PivotItems = new ObservableCollection<StatusItem>();
DataTemplate itemTemplate = App.Current.Resources["PivotItemTemplate"] as DataTemplate;
ListBox itemBox = new ListBox();
itemBox.ItemsSource = PivotItems;
itemBox.ItemTemplate = itemTemplate;
CorePivotItem = new PivotItem() { Header = header, Content = itemBox };
Now when I ever I add objects to PivotItems, nothing ever shows up in the UI.
Sorry for not being clear the first time - Here is the DataTemplate binding -
<DataTemplate x:Key="PivotItemTemplate">
<StackPanel >
<Image Source="{Binding URL}" ></Image>
<TextBlock Text="{Binding Text}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
I am adding the PivotItems to another OC which is binding to a Pivot control. All listings show up fine when I flick across PivotItems. Basically what I am guessing is that the OC is not triggering a refresh on the ListBox. Could I potential use BindingExpressions to force Refresh the list?
Your code doesn't show adding the newly create PivotItem to the Pivot. Is this what you're not doing.
This does of course assume that CorePivotItem is not already defined elsewhere.
Can you show your XAML and other C# code so we get the full picture.

Resources