Toggle AppShell on button click in Xamarin.forms - xamarin

I have AppShell that I pull from the side to show but I want to achieve this on button click to toggle AppShell. I am not using the default AppShell navbar so I disabled the Shell.NavBarIsVisible="False" since its not needed.
I want to achieve this with the custom button to toggle AppShell.

You can open it with this , true to open or false to close
private void Bottommenu3_Clicked(object sender, EventArgs e)
Shell.Current.FlyoutIsPresented = true;
}

Related

Navigate within modal dialog using shell

I'm using shell to navigate in my Xamarin Forms app. I want my settings to be in a Modal dialog which is navigated to by calling PushModalAsync. In that settings page I want to navigate to other pages, eg password change. But since I'm not using NavigationPage I cannot get it to work.
How do one use Shell with Modal and navigate within that Modal page?
I can get it to work by setting my SettingsPage as a new MainPage. But then I don't get the modal navigation animation.
using NavigationPage will probably solve the problem but then I will
no longer use Shell which I want to use.
I think wrap your Settings page in a NavigationPage would solve your problem. You can still use Shell after using NavigationPage.
For example, you can do some push actions in the SettingPage:
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new BearDetailPage());
}
In the BearDetailPage, if you want to use Shell, you can dismiss the SettingPage by send a message usingMessagingCenter:
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PopToRootAsync(false);
MessagingCenter.Send<BearDetailPage>(this, "BackToShell");
}
And in the SettingPage, subscribe that message:
public SettingPage()
{
InitializeComponent();
MessagingCenter.Subscribe<BearDetailPage>(this, "BackToShell", (sender) =>
{
// Do something whenever the "BackToShell" message is received
this.Navigation.PopModalAsync();
});
}
If you don't want the navigationbar in the SettingPage, you can just hide it.

Xaml Button is "clicked" if it's pressed-and-hold on a touch screen

I am developing a Windows UWP App with C++. I want to add a button that can either be left-clicked or right-clicked and do corresponding task.
The button works perfectly on normal devices with mouse. Unfortunately on touch screen, if users press-and-hold the button, both left-click and right-click events are triggered.
I am using "Click" to handle the left click event and "RightTapped" to handle the right click event. Any suggestion on how to disable the left-click event when users press-and-hold the button? Thank you!
The XAML code is short:
<Button x:Name="m_NewPageButton"
Content="New Page"
Height="48"
Width="199"
Click="OnClick"
RightTapped="OnRightClick"/>
And here's the cpp code:
void MainPage::OnClick()
{
// Left click task
}
void MainPage::OnRightClick()
{
// Right click task
}
Edit:
Thanks guys, the solution is to change the left click handler to , which will not be triggered by press-and-hold.
Hacky but works...
private bool rightClicked;
private async void Button_Click(object sender, RoutedEventArgs e)
{
if (rightClicked)
return;
await new MessageDialog("left").ShowAsync();
}
private async void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
rightClicked = true;
await new MessageDialog("right").ShowAsync();
rightClicked = false;
}
I'm guessing this is a flaw in the design.. :(
Actually... If you use the button's Tapped and RightTapped events it works as it should. So in this case just replace Clicked with Tapped and all is well... Then you can ignore the hack I put above.
You can use the Holding event to detect a tap and hold. Use the Tapped event for a single tap (or click). The Tapped event should only fire for touch on a quick tap and release. The mouse specific click will raise Tapped but a touch tap-and-hold will not.

Navigation back between two fragment xamarin android

MainActivity
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
ActionBar.SetDisplayHomeAsUpEnabled (true);
drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);
navigationView = FindViewById<NavigationView> (Resource.Id.nav_view);
Event click on navigatonView
CreateFragments();
LoadInditialFragment ();
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
Onefragment
Twofragment
Navigation back from second Fragment to first fragment(navigation back on toolbar).??? MainActivity I have a button menu on toolbar.
I want to replace menu icon into back icon when It is standing at second fragment.
Download back arrow and save as navBack.png
Then in SwitchFragment method where we navigate between fragments
switch (FragmentId) {
case Resource.Id.nav_home:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
transaction.Show (homeFragment);
transaction.Commit ();
break;
case Resource.Id.nav_genre:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.navBack);
transaction.Show (genresFragment);
transaction.Commit ();
break;
}
In Your MainActivity do this in OnCreate:
SupportFragmentManager.BackStackChanged += HandleBackstackChanged;
Implement the HandleBackstackChanged method like this
private void HandleBackstackChanged(object sender, EventArgs e)
{
ActionBar.SetDisplayHomeAsUpEnabled (SupportFragmentManager.BackStackEntryCount > 0);
}
What this will do is toggle between the Menu button and the Back button based on the BackStack count of the FragmentManager.
NOTE:
I am assuming you are using the Support library for backwards compatibility of Fragments. If you aren't using the support library, just use FragmentManger instead of SupportFragmentManager.

How to enable PhoneApplicationPage_BackKeyPress event when set textbox.Focus() on textbox_LostFocus event in windows phone 8

How to enable
PhoneApplicationPage_BackKeyPress
event when set textbox.Focus() on textbox_LostFocus event in windows phone 8.
I want to show keyboard when i add some item into listbox from textbox. Listbox gets update but my keyboard always gets hide on button click.
I want to make it open all the time till i press back key.
Thanks,
Nishant
you can get BackKeyPress Event by :
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
}
You can write textbox.Focus() at the end of button click when all work is done
try this :
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
ListboxName.Items.Add(TextBoxName.Text);
TextBoxName.Text = "";
TextBoxName.Focus();
}
I have implemented. Its working...

How to go to an xaml page by clicking on the button in WebBrowser control in Windows Phone 7 or 8

I have a XAML Page with a WebBrowser tag. WebBrowser has few text boxes and a button, here my question is after clicking on that button i have to go to a XAML page. How can i do this?
By clicking the button in WebBrowser, i want to go to a XAML Page which is in solution file.
Please help me on this.
I believe you can solve this by listening to the WebBrowser.Navigating event. First do:
myWebBrowser.Navigating += myWebBrowser_Navigating;
Then in the handler method check if the uri navigated to is the pointed to by that button:
private void myWebBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if(e.Uri.AbsolutePath == URI_OF_BUTTON) {
NavigationService.Navigate(new Uri("/otherPage.xaml", UriKind.Relative));
}
}
It sound like Page Navigation.
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Pasta.xaml", UriKind.Relative));
}

Resources