I am new to Xamarin forms and have directed to a navigation page from my main page, I'd like the title to appear on the same line as the back button but it's currently appearing on the line below, like this -
https://i.imgur.com/lpsJjle.png
I am using the following code to display the title -
<NavigationPage.TitleView>
<StackLayout>
<Label
Text="About" TextColor="{StaticResource lightGreen}">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String"
Android="GothamRoundedMedium.ttf#GothamRoundedMedium"
iOS="GothamRoundedMedium">
</OnPlatform>
</Label.FontFamily>
</Label>
</StackLayout>
</NavigationPage.TitleView>
and this code to navigate to the about page -
Navigation.PushAsync(new NavigationPage(new Survey2()));
Any help would be much appreciated!
With new NavigationPage you are again creating a new NavigationPage.
So,just use:
Navigation.PushAsync(new Survey2());
If you need to use Modal,use this:
Navigation.PushModalAsync(new NavigationPage(new Survey2()));
Related
Right now my ContentView (acts like a pop up window) stacks on top of my grid, see code below:
<StackLayout>
<ContentView>...</>
<StackLayout>
<Grid>...</>
</StackLayout>
</StackLayout>
The grid is a form, so when I press a button in my form, I want a new pop up window (the contentview) to be above the grid, in the center of the screen. The idea is that you can still see some of the form behind the contentview.
How do I put contentview in the front and not stacked on top of my grid?
Here's my contentview
<ContentView x:Name="popupAddDetails" AbsoluteLayout.LayoutBounds="0,0,1,1"
VerticalOptions="Center" HorizontalOptions="Center">
PS: I'm new to this environment and still learning. Thankful for any help
I tried to make a stacklayout above my first stacklayout with my grid in it and then set vertical and horizontal attributes in my contentview to center. But it just stacked upon my inner stacklayout.
You could simply use Xamarin Community Toolkit Popup to make it.
First of all, add a new Nuget named Xamarin.CommunityToolkit to your project.
Then, create a popup page which will be shown when you click a button. This is much similar to creating a ContentPage.
<?xml version="1.0" encoding="UTF-8" ?>
<xct:Popup
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ContentDemo.CommunityPopupPage"
xmlns:xct="clr- namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit">
<StackLayout WidthRequest="200" HeightRequest="200"BackgroundColor="Red"HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="hello"/>
</StackLayout>
</xct:Popup>
The .cs may be something like this:
using Xamarin.CommunityToolkit.UI.Views;
namespace ContentDemo
{
public partial class CommunityPopupPage : Popup
{
public CommunityPopupPage()
{
this.Size = new Size(300, 300); //you could change the size of the popup
InitializeComponent();
}
}
}
Finally, you may want to open this popup page via a button clicked event. Don't forget to add this line:
using Xamarin.CommunityToolkit.Extensions;
void Button_Clicked(System.Object sender, System.EventArgs e)
{
App.Current.MainPage.Navigation.ShowPopup(new CommunityPopupPage());
}
I created this demo and it worked well. You could refer to Xamarin Community Toolkit Popup and Getting Started with the Xamarin Community Toolkit for more information.
====================update =====
2.Using outer layout as a Grid instead of a StackLayout might be an alternative. Just something like this:
<Grid x:Name="outerGrid" VerticalOptions="Center" > //this grid includes the grid and the contentview to be shown
<Grid x:Name="innerGrid">
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
...
</Grid.ColumnDefinitions>
</Grid>
<ContentView>
... // design the content
<ContentView />
</Grid>
In this way, the ContentView will be placed above the innerGrid. But I prefer using a popup page.
Hope it works for you.
I have content page in my xaml file. I have a Stacklayout with orientation vertical in it. I want to put a dialog in middle of content page above this stacklayout. Please suggest some way. Thanks in advance!
An easy way to provide dialogs that feel native to the platform your on is through using the UserDialogs plugin.
If you want to create something of your own you would probably have to come up with something like this:
<Grid>
<StackLayout>
...
</StackLayout>
<Grid IsVisible="{Binding ShowMessage}">
<Label Text="Message" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>
</Grid>
The nested Grid will act as an overlay of sorts spanning your entire page.
i am using xamarin forms(PCL) and execute the App using Windows phone emulator
i created a master detail page
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Orientation="Vertical">
<Button Text="buttonOne"/>
<Button Text="ButtonTwo"/>
<Button Text="ButtonThree"/>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:MasterPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
the details page is
<StackLayout>
<Label Text="Hello World"/>
<StackLayout>
<maps:Map WidthRequest="320" HeightRequest="200" />
</StackLayout>
</StackLayout>
it stops at
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached)
global::System.Diagnostics.Debugger.Break();
};
#endif
and return this exception( Native View = Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057.)
Note:
if i remove the WidthRequest and HeightRequest of the map it works
but the map would not appear.
And this Exception Takes place only when navigate to the master
detail page.
So this resolves to not being a problem with the Maps part specifically but an issue with Navigating to Master Detail pages, since PushModalAsync(...) puts the Master Detail Page on top of a new Navigation stack instead of pushing it onto the top of the current Navigation stack which is what PushAsync(...) does.
Here's a link to a Xamarin Forms Forum question that appears to have the same problem:
https://forums.xamarin.com/discussion/21461/navigation-pushasync-not-working
Apparently MasterDetail pages do not like being navigated to, and both Android and iOS prefer to have it as the root page. That isn't to say this is impossible to do, I believe it just has to be done a little differently. Some dependecy injection/custom rendering might help here.
I found this Xamarin Forms article very useful when learning about Navigation, might help you out as well:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/hierarchical/
I am attempting to make a multipage app and would like to use a common navigation toolbar across all pages. The page includes:
<Page.TopAppBar>
<AppBar >
<StackPanel Orientation="Horizontal">
<Button />
</StackPanel>
</AppBar>
</Page.TopAppBar>
In App.xaml I can define the AppBar that goes into the Page.TopAppBar:
<Application.Resources>
<AppBar x:Key="CommonAppBar" x:Name="AppBarCommon">
<StackPanel Orientation="Horizontal">
<Button />
</StackPanel>
</AppBar>
</Application.Resources>
But how can I use this AppBar defination in the Page xaml?
You can use the Frame control on one page and show another your pages inside that frame. Then you can add an AppBar to this page.
By the way, the AppBarButton is the button that is used inside an AppBar, not StackPanel and Buttons (your approach will still work, but if you expect the same behaviour and look as in other UWP apps, it's easier to use AppBarButtons).
I would like to switch many pages between in single xaml page on click on segment control.
I want make a page like upper part of page is with segment control and below this control having simple layout that is using for replace or switch a other pages in same that below position change but upper part is still remains for next page switching.
So, i would like to code for switching page with using segment control in xaml in xamarin.forms.
There is a nuget package FreshEssentials. It has cross-platform implementation of segmented control button. Find this Github repository to understand the implementation.
Hope this help !
Refer bellow link to implement custom segment control using XAML code and Cs Code
https://github.com/sam-ss/Custom-Segmented-Control-Xamarin-Forms
Hope This Help you!
you can install from nuget this library "Plugin.Segmented.Control"
from this tutorial https://www.c-sharpcorner.com/article/segment-control-in-xamarin-forms/
and your xaml:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:control="clr-namespace:Plugin.Segmented.Control;assembly=Plugin.Segmented" xmlns:iOSForms="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" iOSForms:Page.UseSafeArea="true" xmlns:local="clr-namespace:XFSegmentControlDemo" x:Class="XFSegmentControlDemo.Views.HomePage">
<StackLayout VerticalOptions="FillAndExpand" Padding="30" Spacing="20">
<Label Text="Segmented Control" FontSize="30" TextColor="White" HorizontalOptions="CenterAndExpand" />
<control:SegmentedControl x:Name="SegmentedControl" SelectedSegment="{Binding SegmentSelection}" TintColor="White" SelectedTextColor="BlueViolet" DisabledColor="Gray" Margin="8,8,8,8">
<control:SegmentedControl.Children>
<control:SegmentedControlOption Text="Item 1" />
<control:SegmentedControlOption Text="Item 2" />
</control:SegmentedControl.Children>
</control:SegmentedControl>
<Label Text="{Binding SelectedSegment}" FontSize="40" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
put this code in your viewModel
int _selectedSegement;
public int SelectedSegment {
get {
return _selectedSegement;
}
set {
_selectedSegement = value;
switch (SelectedSegment) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
OnPropertyChanged("SelectedSegment");
}
}
and the last step put this in your appDelegate
global::Xamarin.Forms.Forms.Init();
SegementedControlRenderer.Initialize();
LoadApplication(new App());