Navigation between views Xamarin Forms - xamarin

I have simple Click event and want to navigate between views, but I get annoying slide up animation even that I have "false" as a parameter for animation in function. Is there any way to turn of animation effect when browsing between views in Xamarin Forms?
Thank you!
void Button_Clicked_Signup(System.Object sender, System.EventArgs e)
{
Navigation.PushModalAsync(new Signup(), false);
}

Your app is doing exactly what you're asking it to do. That annoying slide up animation is called Pushing a Modal which is happening since you are using the PushModalAsync function.
You need to the documentation and understand Hierarchical Navigation.
To fix it, you need to
Create a NavigationPage first
Pass in your current page into that
Use Navigation.PushAsync instead of Navigation.PushModalAsync

Related

MAUI CarouselView: how to imitate swipe effect in code? Swipe animation does not happen

.NET Maui CarouselView. In certain situations I want my app to take the user to the next card automatically. If I update CarouselView.Position or CarouselView.CurrentItem in code behind, it "jumps" to the next card immediately, no animation. Is it possible to imitate user's swipe? Or as a workaround, maybe somehow apply non-native-CarouselView animation manually to the CarouselView. Please advise.
The CarouselView contains a ScrollTo method that will animate the scroll for you. You either scroll to an index or a specific item.
Give your CarouselView a name in the XAML, and then in the code behind call the ScrollTo.
To scroll to an index:
carouselView.ScrollTo(6);
To scroll to a specific item:
var viewModel = BindingContext as MyViewModel;
var item = viewModel.Items.FirstOrDefault(m => m.Name == "TheBest");
carouselView.ScrollTo(item);
These methods have to be called from the code behind, so if you're using a MVVM approach, you'll need to fire an event or command from your VM for your code behind to act on.
For additional info, take a look at the ScrollTo method docs from Microsoft.

Xamarin Forms Using page transitions

I have a problem. I created an app, that uses a wizzard to set some of your settings, so to do that, I created a navigation page. In that navigation page I created my own NavigationBar with a back and next arrow and these functions:
private void arrowBack_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
private void arrowNext_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Devices(), true);
}
But now every page slides in from the bottom, but I want them to slide in from the right and for back I want them to slide in from the left. Now I already found a few projects to create this like this: https://github.com/jsuarezruiz/xamarin-forms-page-transitions, but I was wondering if there isn't something much simpler, because it looks to me like a very wanted feature!
Any suggestions how to make NavigationPage animations from the sides?
The navigation that you are experiencing it is due to the fact that you are using PushModalAsync and PopModalAsync.
Using this your new page will come from the bottom of the screen.
If you change your code to use PushAsync and PopAsync instead (without the word Modal), you will get the navigation that you are looking for.
To get the sliding animation you should set the animation parameter to true, like this:
Navigation.PushAsync(page, true);

Is there an event name for this action?

Is there a ScrollView event in xamarin that is triggered when the user forces scroll up and scroll is already at top? Many apps uses this as the "command" to update the page.
Currently, there is no PullToRefresh property or RefreshCommand for a ScrollView built into Xamarin.Forms. However, It does exist on ListView as shown in the docs, which you might be able to use instead depending on your needs.
Also, it does look like there is a PullToRefreshLayout opensource project created by James Montemagno you might be able to use to easily implement pull to refresh with a ScrollView, but it has been a while since it's last been updated.
You can use the Scrolled event handler. If the ScrollView is already positioned at the top of the contents and the user "pulls down" then Y amount will be either 0 or negative (I know this will work on Android and iOS, not sure about UWP and others).
scroll.Scrolled += (object sender, ScrolledEventArgs e) =>
{
if (e.ScrollY <= 0)
{
// scrolled when already at top of list
}
};

Place a timer in a Xamarin Carousel page

I would like to place a timer in a Xamarin Forms carousel page, to make the 'swipe' happen automatically if the user does nothing.
Being new to Xamarin I'm not entirely sure if I can do this as I would outwith Xamarin, by creating a System.Timer in code-behind.
The auto swipe should happen after 3 seconds, and swipe through the carousel at 3 second intervals.
Can anyone tell me if this is a viable approach?
Solved it by using:
Device.StartTimer(TimeSpan.FromSeconds(3), () =>
{
// run swipe code
Task.WaitAll(_scvm.MoveNext());
return true;
});
After the InitialzeComponent() line

How to stop the WP7 pivot control handling the Flick Gesture event in Silverlight Toolkit

I have a Pivot Control in my WP7 app that by nature responds to left and right swipes to move between the pivot items.
I then want to use the Flick Gesture on a UserControl (a small UI segment on my page) for something else.
My user control does handle the event but so does the Pivot control, so it navigates to the next item. I have not figured out how to stop the event when the usercontrol handles it.
Is it possible to use a sub control with the flick gesture within a WP7 Pivot Control?
eg:
private void glBlinds_Flick(object sender, FlickGestureEventArgs e)
{
//do stuff
e.Handled = true;
}
This solution posted recently seems to be working out for people for dealing with gesture conflicts on pano / pivot. You might like to check it out.
Preventing the Pivot or Panorama controls from scrolling
The short answer is don't put a control which supports a gesture on top of another control which also supports the same gesture.
Please see this answer to a very similar question for a slightly longer response: WP7 Toggle switch in a Pivot control?
I found this works well for incorporating a slider on a pivot item:
LayoutRoot
Pivot
PivotItem
Grid
Scrollviewer
[Content goes here, I use another grid]
Slider
If I skip the grid and place the slider inside the scrollviewer it doesn't work. I stumbled upon this solution as I wanted to support landscape and still have the slider visible / usable.
You might be able to place your small UI segment for the gesture similar to where I placed my slider.

Resources