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
Related
.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.
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
I am building a website using react to implement.First, we scroll the page to the bottom or middle position.Then we click refresh button in the iphone safari browser,page scroll to the permanent position strangely.I have tried to change the flex layout to float layout and add pageshow event listener to set scrollTop zero using
window.scrollTo(0,0)
.But page still stop at the permanent position in safari mobile.
I guess the problem is the page save the position of last view, but when page fresh, the content of the page is not show completely, and then the page could only scroll to the permanent position.At last, the rest part of the page show out.And the pageshow event has been triggered early before the page scroll to the permanent position.
How can I force the page to be scrolled to the top on page refresh except window.scroll? How can I solve this strange behavior of the safari browser?
I have the same issue as you using react on ios safari, the only fixed I found is to use a setTimeout in componentDidMount, but I really don't like this solution
componentDidMount() {
setTimeout(() => {
window.scrollTo(0, 0);
}, 800);
}
Hope it'll help
use window.scroll(0, 0) instead of window.scrollTo()
I'm trying to realize this layout in android wear: Timer Custom App. I think this is like a listview with horizontal orientation, but WearableListView doesn't have this attribute.
Try using a GridViewPager and setting negative page margins :
pager = (GridViewPager) stub.findViewById(R.id.fragment_container);
pager.setPageMargins(0, -30);
You can then implement onClick listeners on the fragments to change the current page by just clicking at the right or left of the page like the native alarm app.
I'm developing a Windows Phone application. When I launch, the splash screen is shown very shortly, and the MainPage.xaml is shown. However, in the MainPage, I setup the camera with the usual code:
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
_photoCamera.Initialized += OnCameraInitialized;
// And other event handling
viewfinderBrush.SetSource(_photoCamera);
}
This is simplified, but it all works. My problem is that this takes a while (mabye 0.5 - 1 seconds, I didn't time it exactly).
So what my user gets is a splashscreen that's so fast, he/she can't see it; and a first page that takes just that tiny fraction to experience it as slightly laggy/slow.
I'd like to change it. Have the splashscreen show until everything is initialized. This has the added benefit of branding for me, and a nice experience for the user.
I've tried this:
Add my splashscreen as image into my MainPage, on top of everything else and hide it when everything is initialized
Add my splashscreen in a popup on my MainPage, and hide the popup when everything is initialized (found that here)
This 'works', but I can see a black flash between the splashscreen and my image/popup. Is there a way to make this transition seamless? Or is this fairly normal behavior in WP7?
Your first option should work - but understand that in one trip through a UI-thread method, the UI doesn't actually update until all the code is executed. So break it up into pieces.
1) Load your MainPage.xaml, which has the splash image filling the screen by default
2) Add an event handler for both OnNavigatedTo and LayoutUpdated. When OnNavigatedTo is hit, set a flag to true. In LayoutUpdated, check for that flag to be true, set the flag to false, then run a Dispatcher.Invoke() call on the method you described above.
3) Remove the image or set it to collapsed after that method is completed.