How to populate Picker items before open, using Xamarin.Forms - xamarin

Using Xamarin.Forms, how do I populate a Picker with items, immediately before the Picker opens?
We have a number of pickers on the same page and it would be inefficient to populate all items upfront, as some of the queries are expensive. For reference, I'm trying to get this working on Xamarin.Android first, and am using the latest stable version - 1.2.36257 at the time of writing.
I've tried:
Focused event - This almost works, but changes to Items are not applied until the next time the Picker opens.
TapGestureRecognizer - The Tapped event doesn't seem to be fired. Perhaps it doesn't work with a Picker.

There's nothing that the Xamarin.Forms Picker exposes from what I can see either, that would allow you to achieve what your wanting.
TapGesture's can be troublesome. For instance I quickly tried it on WindowsPhone, and that is not recognizing the TapGesture either. Your also find some different behavior with different controls as well - with the same response not being uniform across platforms.
I tried hooking into the Picker PropertyChanged / PropertyChanging, and this has the outcome exactly the same as attempting to hook into the Focused event handler that you experienced, with it only working after the picker has initially been displayed.
The only way around this would be to write a custom renderer to achieve what you want to do.
Within that, you could then expose custom events such as OnBeforeAppearing, that would allow you to then pre-load the picker with the items you need from the page at time of use.

Related

Nativescript Vue: How to dismiss searchBar keyboard when scrolling ListView?

I have a SearchBar component and a ListView component. When I tap the search bar, the keyboard comes up but it stays up even if the user decides to scroll ListView under it. I can't seem to find either
1) any event on the ListView that I can trigger the search bar to close on when it's scrolling
--or--
2) any event on the search bar that I can check to see if it's not focused , then close it.
Either of those would be sufficient but I can't seem to find any in the documentation.
Both components are independent of each other, you must call dismissSoftInput() on the search bar upon scroll.
Unfortunately the scroll event is not supported out of the box while using ListView. There is an open feature request on Github, which also discusses how you may implement this event with an override & bit of native code in your project. You may also consider using RadListView, supports scroll events out of the box.

Xamarin Forms - Disable loading spinner on ListView

I have a Xamarin forms app where I'm using ListViews to display some data, with pull to refresh enabled. When the ListView is pulled and starts the refresh it has its own spinner animation. However, this doesn't display when the page first loads, and so I've wired in a separate ActivityIndicator to indicate loading for just the first time. It's styled different though. I would prefer to use the ActivityIndicator, since it's what's used through the rest of the app, but I haven't found a way to disable the spinner animation on the ListView yet. Is it possible to disable it? Any suggestions would be appreciated, thanks!
There are a few ways I can think of to solve this.
Don't use Pull-to-refresh. Xamarin.Forms has this built in and you can't customize it without using renderers and altering controls. Instead, start your refresh another way (ToolbarItem, etc) and continue using your custom ActivityIndicator.
Customize the existing ListViews UIRefreshControl. You may be able to use a renderer or "Effect" to customize the RefreshControl being used by the native control. This would allow you to style it a little close to what your custom indicator looks like.
Change the color of the spinner. This is my least favorite option. You could workaround this by changing the color of the spinner to match the background so you don't see it.

After assigning GetViewForAnnotation, Xamarin.Forms class doesn't receive Click event

I have a Xamarin.Forms page with a map containing numerous pins. I've built a custom iOS renderer to change the image of the displayed pin.
Once I assign the GetViewForAnnotation delegate, my Xamarin.Forms class no longer receives the "Clicked" event. I can access it through the custom renderer, I do believe, but what I want to do when the user taps the title of the pin is push another Xamarin.Forms page to the navigation stack, and I don't know how to give control back to my Xamarin.Forms app from within my Xamarin.iOS app.
I have a feeling I'll need this type of logic in a few other places... where I need to handle a CustomRenderer event but then pass control back to the Xamarin.Forms app for navigation or other purposes.
So I have a couple directions I'd like to go:
1 - More straightforward - get my "Clicked" event to fire in the Xamarin.Forms app when the map's pin is clicked, even though the iOS app is handling the creation of the pin via a CustomRenderer
2 - More advanced and customizable - pass control back to my Xamarin.Forms app (maybe raise an event related to the Renderer level?)
I'd prefer at this time to just get my Clicked event back, but I'm guessing that may not work once I assign the GetViewForAnnotation event in the CustomRenderer.
From what I read, you can detect the annotation click within your renderer.
Within your renderer in the OnElementChanged you can get access to the View in the Xamarin.Forms PCL it relates to.
A few possibilities to consider going forward:-
a) Use MessagingCenter to convey messaging between interests (see
here).
b) Use the standard event raising, i.e. public event
EventHandler<someEventArgs> OnSomeEvent through your View in your
PCL.
c) Use an ICommand approach on your View in your PCL if your
more MVVM orientated, and invoke this way instead.
Once you have your notification back through your View / Page, depending on where your doing things, you can then do a normal navigation based on the information you have been given from your platform-specific renderer in the PCL.

KendoUI version of JQUERY animated side navigation

I am fond of the type of side navigation menu that is common in mobile apps. An example is: http://www.jqueryscript.net/menu/jQuery-Animated-Side-Navigation-Menu-Plugin-Sidebar.html
Which works also for web pages. However, the vast majority of my page is in KendoUI, and I don't want to load another framework just for that.
Is there a combination of tricks with Kendo (draw control for example) that I could use to get the same effect?
Alternatively, I am all wet. I just want a quick way to have a "pop-up" of settings that are only occasionally used, and most of the time save the screen real-estate. So maybe just a button and a pop-up window is the correct approach?
Any advice?

Custom Navigation with Xamarin.Forms

I’m working on an application for Android and iOS, which requires a certain flexibility for one or two views. That’s why we created & implemented a service that translated a basic list of objects into a user interface for both iOS & Android. But now that Xamarin.Forms is released, we decided to replace our service by the one Xamarin provides. I did succeed in creating the views with Xamarin.Forms, resulting in better looking & smoother running pages. But my problem lies in the navigation of it. Here is a little drawing on what I would like to achieve:
I would like my app to start an activity that starts with a custom fragment. After clicking a button on this fragment, I would like the page I created with the Xamarin.Forms api to be added to my current navigation stack! Once the user is finished with the Xamarin.Forms page, it navigates to a second custom fragment, all that without breaking the navigation cycle. Does anybody have an idea on how I can achieve this?
For the iOS developpers: replace Activity with NavigationController & Fragment with ViewController
Take a look at CarouselPage for Xamarin.Forms' own approach. It doesn't look like that's what you need but you can also look at its source code and maybe make a custom renderer yourself.
You may also want to take a look at MVVM
As for the easier/hackier way you'd want to make a button on each page and when the button is tapped execute Navigation.PushModalAsync(nextPage) - there won't be a "< Back" button any more, you may need to implement that yourself if you need it.
If by your meaning of 'current navigation stack' is for using the native Navigation of each platform, then remember that you don't have to use Xamarin.Forms' Navigation Model and functions such like PushAsync.
If you prefer to do Navigation with code specific to each platform then you can do this the same as normal. Just create your stub pages in each platform specific project and set the Xamarin.Forms content for each page from the shared project.
From each platform specific stub page (Activity / UIView / PhoneApplicationPage) you could then execute an Action<> call setting on the shared Xamarin.Forms page to help with the navigation, or alternatively, hook into a custom-event that is raised from the Xamarin.Forms** page back to the platform specific stub page to allow you to do navigation from there.
Like Sten mentioned there won't be any 'Back' button so you will most likely have to do that yourself.

Resources