Include tabbedpage in a Xamarin forms popup - xamarin.forms

I have a popup on click of a list view.
Is it possible to include Tabbed page in the popup with two tabs?

Not sure what effect is your want.Follow is one way :
async void OnAlertYesNoClicked (object sender, EventArgs e)
{
bool answer = await DisplayAlert ("Question?", "Would you like to play a game", "Yes", "No");
Debug.WriteLine ("Answer: " + answer);
}

If you want tabs without having a TabbedPage in Xamarin.Forms, you can use those custom tabs:
https://github.com/roubachof/Sharpnado.Presentation.Forms#pure-xamarinforms-tabs-no-renderers
These are simple xamarin forms views, you can put them everywhere you like.

Related

Xamarin.Forms - Tooltip as menu

I couldn't find it anywhere, so I'm trying this option.
I have an app with frames and when I click on the frame I want a tooltip-like window to come up where the user can select an option. Something like this:
I took a look at Xamarin.Android.Tooltips, but that doesn't seem to be able to handle multiple options to choose from. Are there other packages available which work better for this case?
I hope my question is clear.
Something like this does not exist in vanilla Xamarin.Forms unless you're ready to create your own custom view and platform renderers. You may consider using a NuGet package like ACR User Dialogs which provides many pre-programmed views that would probably satisfy your requirements.
There are many ways to achieve this.
1.Xamarin Community Toolkit PopUp.
There is a sample included in above link,you can check it here: https://github.com/ahoefling/XCT-Popups-Samples?WT.mc_id=xamarin-c9-jamont .
The main code is:
private async void Button_Clicked(object sender, EventArgs e)
{
// uncomment the different types of popups
HelloPopup();
//PositionPopup();
await ReturnValuePopup();
await GenericTypePopup();
}
void HelloPopup() => Navigation.ShowPopup(new HelloPopup());
void PositionPopup() => Navigation.ShowPopup(new PositionPopup());
async Task ReturnValuePopup()
{
object result = await Navigation.ShowPopupAsync(new ReturnValuePopup());
await DisplayAlert("Popup Response", $"{result}", "OK");
}
async Task GenericTypePopup()
{
var result = await Navigation.ShowPopupAsync(new GenericValuePopup());
await DisplayAlert(result.Title, result.Message, result.Ok);
}
2.Display Pop-ups
To display an action sheet, await DisplayActionSheet in any Page, passing the message and button labels as strings. The method returns the string label of the button that was clicked by the user.
A simple example is shown here:
private async void Button_Clicked(object sender, EventArgs e)
{
string action = await DisplayActionSheet("Choose an option", "Cancel", "Delete", "Option 1", "Option 2", "Option 3");
Debug.WriteLine("Action: " + action);
}
3.nuget Rg.Plugins.Popup .
It is a cross platform plugin for Xamarin.Forms which allows you to open Xamarin.Forms pages as a popup that can be shared across iOS, Android, UWP, and macOS. Also the plugin allows you to use very simple and flexible animations for showing popup pages.
For more , check: https://github.com/rotorgames/Rg.Plugins.Popup .

Xamarin virtual keyboard overlaps search component

In my Xamarin project I have a listview with a search box on the bottom. When I go to type in a search value the virtual keyboard overlaps the search box?
I tried to use Content.layout but I can't match the keyboard and search together Is there a way to fix this do I use a popup control?
void InputFocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,-360, Content.Bounds.Width, Content.Bounds.Height));
}
void InputUnfocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,0, Content.Bounds.Width, Content.Bounds.Height));
}
For ios , you can use this plugin, add to your ios project.
https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/KeyboardOverlap
For android, try to add the following code in App.xaml, new App()
Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
If you still have this issue, please provide mode code here, I will try to reproduce your issue at my side.

How to move search icon of search bar at right hand side in xamarin forms

How to move search icon of search bar at right hand side in xamarin forms.
I am looking for android and IOS.
For Android I used SearchBarRenderer With below code which does not worked
Anyone know how to do it?Please help.
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
Control.LayoutParameters=(new ActionBar.LayoutParams(GravityFlags.Right));
}
In android, with a custom renderer, you can use the following code to place the search icon at the right side of your search bar:
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var searchView = base.Control as SearchView;
//Get the Id for your search icon
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
ViewGroup linearLayoutSearchView = (ViewGroup)searchViewIcon.Parent;
searchViewIcon.SetAdjustViewBounds(true);
//Remove the search icon from the view group and add it once again to place it at the end of the view group elements
linearLayoutSearchView.RemoveView(searchViewIcon);
linearLayoutSearchView.AddView(searchViewIcon);
}
}
In the above implementation, I simply removed the search icon from the search bar view group and then added it again to the same view group. This placed the normally first child to the last child, thus placing the search icon at the end.

How to disable left menu in master detail page in xamarin forms?

I have masterdetail page and there is left menu in it. Its working fine during user is on masterdetail page. But When user move from master detail page to simple content page(that is not part of master detail page), on this content page if he swipe from left to right left menu opens.
How I can disable the left menu on this content page? and why left menu is showing on simple content page while it is not part of the master detail page?
If you're still looking for a solution, you can do it like so:
IsGestureEnabled = false;
You can continue to use
await Navigation.PushAsync(new PageWhichWontOpenTheMenu());
To use it, simply get the RootPage (the MasterDetailPage) on the OnAppearing method like so:
protected override void OnAppearing(){
base.OnAppearing();
(Application.Current.MainPage as RootPage).IsGestureEnabled = false;
}
Tell me if it works for you, cheers!
You can only disable the gesture from master details page.
It can be solve by notifying that the current page is not master page:
1)When we are setting the Master details page by
Detail = new NavigationPage((Page)Activator.CreateInstance(page));
IsGestureEnabled = true;// always set it true when setting a page to master page
2)Use MessagingCenter from MasterDetails Page for notifying that the current page is not a master page:(inside the master page constructor)
MessagingCenter.Subscribe<string>(this, "DisableGesture", (sender) =>
{
if(sender == "0")
{
IsGestureEnabled = false;
}
else
{
IsGestureEnabled = true;
}
});
3)when you navigate from a nornal content page,and you dont want to open the master menu from here then notify the master page IsGestureEnabled = false;
//content page OnAppearing method
protected override void OnAppearing()
{
MessagingCenter.Send<string>("0", "DisableGesture");
}
do this for all your content page,where you dont want to open master menu.
****and remember that which pages you are setting as master page,for those pages onappearing method send messaging center with value "1"
protected override void OnAppearing()
{
MessagingCenter.Send<string>("1", "DisableGesture");
}
Thanks
Better yet what you can do in your OnMenuItemSelected event for your SideMenu list is check for the type that you want to Disable the SideMenu for and then set IsGestureEnabled to false when navigating to that page:
private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = (SideMenuItem)e.SelectedItem;
var page = item.TargetType;
if (page == typeof(PageToDisableMenu))
IsGestureEnabled = false;
Detail = new NavigationPage((Page)Activator.CreateInstance(page));
IsPresented = false;
}
I know this answer is late but I hope it helps someone in the future :).
You probably use Detail.Navigation.PushAsync(...) instead of that use Navigation.PushAsync(...)
To really disable, I found one way, use Navigation.PushModalAsync(...). But this way, you don't have the navigation bar at the top anymore. You can build one yourself though.
What worked for was to disable the whole MasterDetailPage with the IsEnabled property.
In may case executing a process from an option menu (not navigation or change the Detail page) and I needed to block any interaction of the user with the page.
Hope this helps.
Regards

Is there a way to disable the background on the DisplayActionSheet using Xamarin Forms?

Issue:
I'm dealing with an issue on how to disable the background on a DisplayActionSheet or DisplayAlert in Xamarin Forms, so the only way the user can "get out" of the popup windows is via the options that the window has prompted.
Here is the screenshot of the problem:
http://postimg.org/image/s16cp66wf/
Do you know if there's a simple way to do this? I've been looking but I couldn't found....
I tried:
Using the methods that came with the control but nothing else came up. What I'm doing right now is to call it till I have an answer.
Code:
From my code behind I call the event
async void OnNextClicked(object sender, EventArgs args)
{
await userValidations.RMLocationServiceWindow();
}
And then I call the popup window
public async Task RMLocationServiceWindow ()
{
string rta = null;
while (rta == null)
{
rta = await App.Current.MainPage.DisplayActionSheet("Do you accept to use the service?", "Cancel", "Continue");
}
}
I couldn't find any that keep the focus on the windows.
Unfortunately this could not be done in displayactionsheet, for you to be able to achieve this, you must create a Modal Page with list where you could be able to disable back button until there is a selection on the list. hope it helps
I think I got your problem. If your problem is about when user not click 'Cancel' or 'Continue' and he click empty space, you wont get value for rta. Think about if user click white space it mean is canceling. This way may help you.
while (rta == null)
{
rta = await App.Current.MainPage.DisplayActionSheet("Do you accept to use the service?", "Cancel", "Continue");
if (rta==null)
rta=="Cancel";
}

Resources