I have an issue that on iOS "More" Tab behave strangely.
Using TabBar and TabbedPages.
When I start the app, I see 4 tabs (1-4) and "More" tab (Which is created automatically by xamarin.forms).
I open the "More" tab to see a list of rest tabs that don't fit. I will see my list "TabPage5" and "TabPage6". (diagram bellow)
I choose for example TabPage5. After that, I will visit one of the tabs which are on the main bar (tabPage1-4).
And when I try to open the "More" tab again to see a list of TabPage5 and TabPage6 -> I am already on the detail of TabPage5 (as last opened from More tab).
It seems that it remembers which I visited last time or I didn't leave that page from the More tab properly.
Tabs bar:
TabPage1
TabPage2
TabPage3
TabPage4
More
TabPage5
TabPage6
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page
Can anyone give me some advice about that. I would like always when I click on tab "More" to see list of tabs which were not default visible.
Thanks
Create a custom renderer of TabbedPage and call PopToRootViewController when you select tabs in "More" tab:
[assembly: ExportRenderer(typeof(TabbedPage), typeof(MainPageRenderer))]
namespace TabbedPageWithNavigationPage.iOS
{
public class MainPageRenderer : TabbedRenderer
{
MainPage _page;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
_page = e.NewElement as MainPage;
else
_page = e.OldElement as MainPage;
try
{
if (ViewController is UITabBarController tabBarController)
tabBarController.ViewControllerSelected += OnTabbarControllerItemSelected;
}
catch (Exception exception)
{
Debug.WriteLine(exception);
}
}
void OnTabbarControllerItemSelected(object sender, UITabBarSelectionEventArgs eventArgs)
{
Debug.WriteLine("Tab Tapped");
var tabbarVC = ViewController as UITabBarController;
var tabIndex = tabbarVC.SelectedIndex;
if (tabIndex == null || tabIndex > 3)
{
tabbarVC.MoreNavigationController.PopToRootViewController(false);
}
}
}
}
Related
I am creating TabbedPage navigation in my project and I have button in page 1, when you click the button it must be go to page 2. It will slide on page 2 of the tabbedpage.
This is how i design my TabbedPage XAML
<TabbedPage
android:TabbedPage.IsSmoothScrollEnabled="True" >
<local:Home Title="Home"/>
<local:MapsLocation Title="Map"/>
<local:FeedbackPage Title="Feedback"/>
<local:Profile Title="Profile"/>
</TabbedPage>
This is my code in my code in button command
public ICommand GotoCommand { get; }
private async void GotoExecute(object sender)
{
var MyObject = (Shop)sender;
await Navigation.PushAsync(new MapsLocation(MyObject.Address));
}
Page 1 when you click the button, It should be slide into the Page 2
Page 2, it should go here when you click the button in the page 1
It should be sliding into child 2 of TabbedPage
How do i achieve this?
If you want to slide to other Tabbedpage, you can use the code below to achieve it. Note that the index of the tab.Children[index] starts from 0 and it should < the count of child tabbedpage or it'll throw the error Index was out of range.
private void Button_Clicked(object sender, EventArgs e)
{
var tab = this.Parent as TabbedPage;
tab.CurrentPage = tab.Children[1];
}
i am currently working on my own TabControl, just to give me more options in customization.
To come along with this, i've made my own TabPage too.
Edit: Rewrote my question with pictures:
I want this Field:
After Clicking on "Collection" you gain a new Box to "Add" and "Remove" the Values
So here's what i've done:
If i now hit "Add" some pages appear, if i hit "remove" some pages disappear.
So far so good.
Clicking on "OK" does not show them up (but they are still there, after reopening the menu)
Now the random stuff happens:
If i press "Cancel" all the 'tabs' are generated.
If i open the menu again, all the "tabPages" are shown as there ClassType.
Here is the code of my TabControl Class
//The List for my TabPages
List<FancyTabPage> listPages = new List<FancyTabPage>();
//My Wrapper to get the Menu for the Designer shown in the Picture
public List<FancyTabPage> Pages
{
set { this.listPages = value; drawTabPages(); }
get { return this.listPages; }
}
//My function to generate the buttons
private void drawTabPages()
{
this.Controls.Clear();
resizeTabPages();
int zaehlerMax = listPages.Count;
for (int zaehler = 0; zaehler != zaehlerMax; zaehler++)
{
this.Controls.Add(listPages[zaehler].PageButton);
}
}
I am working with Xamarin forms and I need to disable the Master page that I use as context menu depending on whether user is logged in or not. I have both Master and Detail pages as separate XAML pages.
<MasterDetailPage.Master>
<view:MenuPage/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<view:MainViewPage
x:Name="MainView"/>
</MasterDetailPage.Detail>
As you might have guessed, I am trying to incorporate MVVM here, so I tried binding visibility (IsVisible) and enabled (IsEnabled) properties of the Master page, however, I still get the undesired black fade effect when pushing navigation button to access my menu. Instead, I need to completely eat up the button press action.
Should your pages be visible whenever the user is connected or not ?
Or do you have a login page at the start of the application for example ?
If you don't have pages that are visible by both connected users or not, you could implement the login page or another page by defining it as ContentPage. It will take all the screen space and hide the navigationBar.
Then after user connect you call a page as MasterDetailPage and then you will have your navigationBar, ...
Don't know if that's what you're looking for but i hope i was able to help you.
This can be achieved with a custom NavigationRenderer, by overriding the Click event of the drawer icon with your custom logic.
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPageRenderer))]
namespace RTW.Mobile.App.Droid.Renderers
{
public class CustomNavigationPageRenderer : NavigationPageRenderer, IMessageSender
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
for (var i = 0; i < toolbar.ChildCount; i++)
{
var imageButton = toolbar.GetChildAt(i) as ImageButton;
var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
if (drawerArrow == null)
continue;
//ensure only one handler is registered
imageButton.Click -= imageButton_Click;
imageButton.Click += imageButton_Click;
}
}
private void imageButton_Click(object sender, EventArgs e)
{
if (!App.IsBlockingConditionTrue)
{
MessagingCenter.Send<IMessageSender>(this, "ToggleMasterIsPresented");
}
}
}
}
Then just subscribe to the message with
MessagingCenter.Subscribe<IMessageSender>(this, "ToggleMasterIsPresented", OnToggleMasterIsPresented);
and handle it.
private void OnToggleMasterIsPresented(IMessageSender obj)
{
_masterDetailPage.IsPresented = !_masterDetailPage.IsPresented;
}
i have make user control and inside that user control takes two buttons name dock and close respectively .
now i want to dock my user control to left when i clicks button dock and close my user control when i clicks button close..
now it works fine.....
but when i add my usercontrol to the toolbox by taking choose items....
then drag and drop my user control to form...
now i have chk on form move event if user control is dock or not...
(i am trying to use by making object of user control but doesnt helps.....)
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Container_User_Control.Container1 obj = new Container_User_Control.Container1();
if (obj.Dock != DockStyle.Left)
{
obj.visible=false;
}
else
{
obj.visible=true;
}
}
Thanks in advanced....
I have no idea why you are using a Mouse_Move event but if I understood your question right then:
When you drag your UserControl from the toolbox to the form, an instance of the usercontrol is created in the form designer code. Something like Container_User_Control1, so instead of using:
Container_User_Control.Container1 obj = new Container_User_Control.Container1();
if (obj.Dock != DockStyle.Left)
{
MessageBox.Show("none");
}
else
{
MessageBox.Show("left");
}
use:
if (Container_User_Control1.Dock != DockStyle.Left)
{
MessageBox.Show("none");
}
else
{
MessageBox.Show("left");
}
C# .Net fw 3.5, in winform in TabControl,
when the user tab out of the last control on a TabPage, then focus should moves to the next page, and focuses the first control in that page, how can i do it?
this is necessary for me because, in a master entry form, there is some compulsory questions which is placed out side of tabcontrol, and some controls which is not necessary all in tabcontrol,
if user visiting each control sequentially then focus should automatically move to next pages, if user want to fill only neccessory infos, then he can submit by clicking save button.
is any suggestion about this.
your question is not accurate
"C# .Net fw 3.5, in winform in TabControl, when the user tab out of the last control on a TabPage, then focus should moves to the next page, and focuses the first control in that page?"
is this a statement or question. I didnt understand. And what is the goal you need ?
If you want the user consequently visit the controls inside the consequent tabs by pressing tab key you can do it by keypressed event in tab control. In the keypressed event you can change the tab programatically.
hope it helps.
The code should be something like this.
Generate keypress event for your tabcontrol and monitor the press of TAB key.
private void tabControl1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.ToString().Equals("TAB") // I dont know what tab key returns. But is hould be something like this
{
tabControl1.SelectedTab = tabControl1.TabPages[1] ;
// now tabpage 2 has the focus
// You can also focus any control you want in here as follows:
tabControl1.TabPages[1].Control["control key"].Focus();
}
}
hope its clear enough
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
namespace CSBSSWControls
{
// Class inhertis TabControl
public class bssTabControl : TabControl
{
private bool AutoTab_;
[DefaultValue(false)]
public bool AutoTab { get { return AutoTab_; } set { AutoTab_ = value; } }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
//property which determines auto change tabpages
if (AutoTab)
{
switch (keyData)
{
case Keys.Tab | Keys.Shift:
{
return SetNextTab(false);
}
case Keys.Tab:
{
return SetNextTab(true);
}
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
private bool SetNextTab(bool Forward)
{
// getting cuurent active control
ContainerControl CC = this.FindForm();
Control ActC = null;
while (CC != null)
{
ActC = CC.ActiveControl;
CC = ActC as ContainerControl;
}
//checking, current control should not be tabcontrol or tabpage
if (ActC != null && !(ActC is TabPage) && !(ActC is bssTabControl))
{
//getting current controls next control if it is tab page then current control is surely that last control on that tab page
//if shift+tab pressed then checked its previous control, if it is tab page then current control is first control on the current tab page.
TabPage NC = ActC.FindForm().GetNextControl(ActC, Forward) as TabPage;
if (NC != null)
if (this.TabPages.Contains(NC))
if (Forward)
{
//selecting next tab page
this.SelectedTab = NC;
return true;
}
else
{
if (this.TabPages.IndexOf(NC) > 0)
{
//selecting pervious tab page
this.SelectedIndex = this.TabPages.IndexOf(NC) - 1;
return true;
}
}
}
return false;
}
}
}