Unable to scroll from tabbed pages in ios - xaml

I have created four tabs
Current
Upcoming
Archived
Cancelled
Each page contains a listview.
Onclick of 1.current is able to scroll list but onclick of other tabs are not able to scroll
Expecting to scroll list onclick of each bottom tab in ios
I tried scrollTO method
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TrainBookingPage : TabbedPage
{
public TrainBookingPage()
{
InitializeComponent();
var navCurrentBooking = new NavigationPage(new CurrentTrainBooking());
navCurrentBooking.Title = " Current";
var navUpcomingBooking = new NavigationPage(new UpcomingTrainBooking());
navUpcomingBooking.Title = "Upcoming";
var navArchivedBooking = new NavigationPage(new ArchivedTrainBooking());
navArchievedBooking.Title = "Archived";
var navCancelledBooking = new NavigationPage(new CancelledTrainBooking());
navCancelledBooking.Title = "Cancelled";
Children.Add(navCurrentBooking);
Children.Add(navUpcomingBooking);
Children.Add(navArchivedBooking);
Children.Add(navCancelledBooking);
}
}

Related

How to set focus to an element inside of user control on UWP?

I created my own UserControl, inside of it, I placed a ListView. But When I set the UserControl to show, I can't set focus to ListViewItem. The Focus is still in the original page.
For how to show my UserControl, I use Popup.
Popup popup = new Popup();
popup.Child = this;
popup.IsOpen = true;
Setting a Focus for a ListView takes place when the ListView has been loaded into the visual tree and ready for interaction.
We assume that you have created a UserControl that contains a ListView, then the method for setting the Focus for the ListView should be done in the UserControl_Loaded or ListView_Loaded event.
public PopupControl()
{
this.InitializeComponent();
// Data init
var _popup = new Popup();
_popup.Child = this;
_popup.IsOpen = true;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
TestListView.Focus(FocusState.Keyboard);
}
Best regards.

How to hide stacklayout if user clicked somwhere else on screen

I createt ResourceDictionary in App.xaml file for application header.
In header I created two dropdowns menu (with stacklayouts and grids).
First is for some user informations and second one is for search.
By default these dropdown menus are hiden.
Max one may be visible if user click on user-icon or on search-icon.
So in HeaderViewModel I cratet these two methods:
private async void AccountInformationAsync()
{
var userService = await UserService.GetUserData();
Username = userService.Username;
DisplayName = userService.DisplayName;
Status = userService.Status;
Influence = userService.Influence;
MTP = userService.MTP;
VisibilityInformation = !VisibilityInformation;
if (VisibilityInformation == true)
{
VisibilitySearch = false;
}
}
private void Search()
{
VisibilitySearch = !VisibilitySearch;
if (VisibilitySearch == true)
{
VisibilityInformation = false;
}
}
This works fine... If user click on user-icon user info will show up and if user then click on serach-icon info will hide an search menu will show up.
So, my question is how to hide any of these menus if user click somewhere else on the screen?
You need to add an TapGestureRecognizer on the Main Layout View of the Page. And on the Tap of it you can use Command and Hide both the dropdown Menu.
private void HideDropDowns()
{
VisibilitySearch = false;
VisibilityInformation = false;
}
HideDropDowns should be the Method assigned to the Command in the TapGestureRecognizer.

How to access control on current TabbedPage?

I have a tabbed page with a stacklayout that I populate with some child controls. The page originally had no navigation but now I've added the tabbed page (created programmatically in the app.cs) it means that the method below is unable to populate the selected tabbed page's stacklayout.
I need to know how to access the current tabbed page and then add the items to the stacklayout.
public static void addToReadout(string name, string time, string inout)
{
try
{
Label label1 = new Label { Text = name + " Successfully clocked " + inout + " # " + time, TextColor = Color.Black };
StackLayout sl = new StackLayout();
var mp = (MainPage)App.Current.MainPage;
if (mp.readOut.Children.Count() < 7)
{
mp.readOut.Children.Add(label1);
mp.readOut.Children.Count();
}
else
{
mp.readOut.Children.RemoveAt(0);
mp.readOut.Children.Add(label1);
mp.readOut.Children.Count();
}
}
catch (Exception ex)
{
ErrorRepository.InsertError(ex.ToString());
}
}
This issue is with this row since changing to a tabbed page setup:
var mp = (MainPage)App.Current.MainPage;
TabbedPage has a CurrentPage property that will return a reference to the current active page.
If your MainPage inherits from TabbedPage, you can do this
var mp = (MainPage)App.Current.MainPage;
var current = mp.CurrentPage;
Edit: based on the code you pasted in the comments
var mp = (TabbedPage)App.Current.MainPage;
var main = mp.CurrentPage;

Xamarin forms: Multiple navigation patterns in the same app

Can we have multiple navigation patterns in a single app?
In my app.xaml page I added a function
void SetUpNavigation()
{
var page = FreshPageModelResolver.ResolvePageModel<LaunchPageModel>();
var navPage = new FreshNavigationContainer(page);
MainPage = navPage;
}
But after a user signs in I want to use master detail page. Is there a way to do that ??
Yes. You just have to set the MainPage of your app again. In our projects, we use a helper class which have a method Restart with following logic:
public static void Restart(View view, NavigationType navtype)
{
// Reset the mainpage depending on the navigation type
if (navtype == NavigationType.RestartWithMasterPage)
{
Application.Current.MainPage = new MasterPage(view);
}
else if (navtype == NavigationType.Restart)
{
Application.Current.MainPage = new NavigationPage(view);
}
else
{
// Just show the page
Application.Current.MainPage = view;
}
}
The NavigationType is an enum:
public enum NavigationType
{
Normal,
Restart,
RestartWithMasterPage
}

How to use CharmFlyoutLibrary with master page?

I have a Windows 8 app, and recently I refactored it to use a 'master page'. This means that there is one 'layout' that has a few generic components such as the header and footer. In that layout, I have a Frame. Every time I want to show a different view, I load it in the frame.
This means that my startup screen is no longer of type Frame but of type Layout, which is a LayoutAwarePage. This is how I initialize it in App.xaml.cs OnLaunched:
Layout rootFrame = Window.Current.Content as Layout;
if (rootFrame == null)
{
rootFrame = new Layout();
Here comes the problem: I have a charms flyout that contains a few items like Settings. I made a nice view (Flayouts.xaml) that contains the layout of these flyouts. The code behind for that view looks like this:
public Flyouts()
{
InitializeComponent();
SettingsPane.GetForCurrentView().CommandsRequested += Flyouts_CommandsRequested;
}
void Flyouts_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
// add some commands
}
And this is how you'd get this to work in your app:
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new CharmFlyoutLibrary.CharmFrame { CharmContent = new Flyouts() };
What they're doing here is assigning a Frame to 'rootFrame'. However, since I switched to a master page, I no longer have a Frame but a Layout/LayoutAwarePage type, so I can't assign the CharmFrame to it. How do I overcome this problem?
Anyone?
When navigating inside a frame the page that you navigate to is placed inside the navigate the Content property.
So if you navigate to you Layout first, then the content will be filled with your page and you can navigate to your child page's. I've placed a example below
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null) {
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
//Associate the frame with a SuspensionManager key
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) {
// Restore the saved session state only when appropriate
try {
await SuspensionManager.RestoreAsync();
} catch (SuspensionManagerException) {
//Something went wrong restoring state.
//Assume there is no state and continue
}
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null) {
if (rootFrame.Navigate(typeof(Layout))) {
var secondFrame = rootFrame.Content as Layout;
if (!secondFrame.ContentFrame.Navigate(typeof(YourPage)) {
throw new Exception("Failed to create initial page");
}
}
}