Not sure why this is happening, but (sometimes) when I change the orientation of a device, this is the output I get:
Only appears to be happening on iPad. Not iPhone. Any insights?
Could be a bug in the binding of a ObservableCollection to a ListView.
You could force a refresh in the ListView by overriding the OnSizeAllocated of the current ContentPage.
protected override void OnAppearing()
{
base.OnAppearing();
ExampleListView.ItemsSource = null;
ExampleListView.ItemsSource = ObservableCollection;
}
Ended up navigating back to the same page to avoid this. Seems something in my code or perhaps a limitation in Xamarin, I have a complex set up for this so that's possible.
Related
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 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);
I have a Forms application which works good but I notice the background colors appear set incorrectly for a fraction of a second as the page appears.
I have this code for my OnAppearing
protected override async void OnAppearing()
{
base.OnAppearing();
Subscribe();
vm.Theme = Settings.th.ToString();
await SetCardButtons(Settings.cc.Text());
}
Can someone explain what happens in the base.OnAppearing() and should this be the first or last line in my override?
what happens in the base.OnAppearing()
OnAppearing is a virtual method in the Page base class, that does not contain any code (but that does not mean it does not do anything).
Depending upon which Page subclass you are using, different things might be performed, like the MasterDetailPage performs logic to determine if it should be displayed as a splitview (side-by-side) mode, the native iOS code would do this on an iPad, ....
should this be the first or last line in my override?
Normally this would be called first in your override to allow any custom subclass code to setup the UI properly.
In my Xamarin forms application, there are multiple ListView controls inside a ScrollView. But in android the scrolling is not working for ListView. Is there any alternative solution?
You SHOULD NOT include ListViews into ScrollView as it system will confuse scrolling behavior of those two.
You need to redesign your page with this in mind.
Example:
1) Use ListViews inside StackLayout
2) Use TableViews inside ScrollView
You can simply do with set 'NestedScrollingEnabled' property true for native side.
For xamarin forms you can create a custom renderer and set 'NestedScrollingEnabled' property true
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var listView = this.Control as Android.Widget.ListView;
listView.NestedScrollingEnabled = true;
}
}
ListView implements its own scrolling that might conflict with the ScrollView.
If you need to be able to scroll both lists in the same ScrollView you could for example create custom views (instead of using cells), placing them in a StackLayout inside a ScrollView
More about ListView performance, they even explain why you shouldn't place a ListView inside a ScrollView
Have you looked into using one listview with groups instead of multiple listviews?
I use any row of grid it will fix to that height & listview will not scroll
First, SelectedIndex is not exposed in markup, so you have to do it in code behind, right?
Second, I have set the binding in code behind:
Binding binding = new Binding("Main.PanoSelectedIndex.ObservedObject");
binding.Mode = BindingMode.TwoWay;
rootPano.SetBinding(Panorama.SelectedIndexProperty, binding);`
(ObservedObject implements iNotifyChanged)
The binding path points to my Main view model, and I can see that the PanoramaItem is updating the binding. However,the panorama does not respond when something else (a MVVM Light command) changes the binding. Any ideas?
Thanks,
Roger
To quote from the Windows Phone Developer FAQ
Panorama is designed so the user is in control, there fore you cannot set SelectedIndex programmatically, or force a navigation to a panorama item.
You can set the DefaultItem so that when your panorama is first launched, the panorama navigates to that item, but you can’t navigate programmatically beyond that. DefaultItem can also be used so that a back navigation feels like the item where the user was at did not change.
UPDATE: You can use the DefaultItem to save/restore the selection for a Panorama as shown below (code from Jeff Prosise's recent blog post):
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// Save the Panorama control's SelectedIndex in page state
State["Index"] = PanoramaControl.SelectedIndex;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Restore the Panorama control's SelectedIndex
if (State.ContainsKey("Index"))
PanoramaControl.DefaultItem = PanoramaControl.Items[(int)State["Index"]];
}
As far as I know SelectedIndex is a readonly property in Panorama ( Weired why WP7 SDK made it readonly). So you will get only UI change back to your VM, and you cant update UI through the VM propertychange.
And DefaultItem is the property which used to set the index programatically.
Again the issue of programatically setting an already instantiated Panorama is that, the alignment of the Title and Panoramaitem wont be in sync. Anyway I am not discouraging but there is still some chance of hack there.