I'm trying to change my MainPage, according to which page are marked in my RadioButton Group, in my settings. So if is marked the first will be "APage", else, "BPage".
But when I try to change MainPage = new AppShell(); it just ignore and don't go to another page.
My standard MainPage is registered as:
<ShellContent Title="{x:Static resource:AppResources.home}" Icon="home_icon.png" Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" />, but I tried to remove this Route and do something like this:
DatabaseAccess DAO = new DatabaseAccess();
if (Convert.ToInt32(DAO.GetRadioValue()[0].RadioButtonValue) == 1)
category.Route = "MainPage";
else
home.Route = "MainPage";
but it still doesn't work.
Even if I go to the code-behind of my standard MainPage and put Shell.Current.GoToAsync(nameof(CategoryPage)); do nothing.
Any ideas?
You can use <ShellContent ... Route="xxx" /> on the xaml page or use Routing.RegisterRoute("xxx", typeof(xxx)); on the cs page to register Route.
Then check your DAO.GetRadioValue()[0].RadioButtonValue value and use await Shell.Current.GoToAsync("xxx"); for page jump.
You can check this link (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation) for more information.
Related
When using the FormsApplication base class with a brand new Xamarin.Forms app using Caliburn.Micro, I end up with an empty navigation bar at the top of my screen. I assume it's being created by Caliburn.Micro somehow, because an out-of-the-box Xamarin.Forms app doesn't have that.
Is there any way I can use Caliburn.Micro with Xamarin.Forms without this navigation bar?
I have not used Caliburn.Micro, but I am assuming that it is wrapping your page with a NavigationPage, as what you describe is what would happen if so.
You should be able to hide that navigation bar by setting a simple attribute in your page like so:
<ContentPage NavigationPage.HasNavigationBar="false"
..... >
</ContentPage>
If you are not using XAML pages and doing all of your UI in code instead, then you can do it this way within your page constructor:
NavigationPage.SetHasNavigationBar(this, false);
If you are using a Shell, (if you chose any of Visual Studios three Templates when first creating your project, you probably are) NavigationPage.HasNavigationBar="False" won't work. Try adding this line of code to each of your ContentPages
Shell.NavBarIsVisible="False"
This drove me nuts for a while as every answer I've seen for the code behind is a partial answer.
Lets say in your App.Xaml.cs file you have your NavigationPage constructor set like this:
MainPage = new NavigationPage(new Astronomy.MainPage());
You then have to go into the MainPage code behind and add code to remove the NavBar: you can't add the line to the app constructor.
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
So glad I finally figured this out! It's been causing me a headache for a while!
It works for me:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility =
(StatusBarVisibility)uiOptions;
}
If you are using Xamarin Forms 3.x try this in the constructor
SetValue(NavigationPage.HasNavigationBarProperty, false);
InitializeComponent();
After updating the MvvmCross nuget packages(to 8.0.2) and Xamarin Forms neget packages (to 5.0.0), I need to put this option explicitly.
put NavigationPage.HasNavigationBar="False" on your xaml ComtentPage
or MvxContentPage
New Here! My first comment
Just too confirm that "Cedric Moore"s Answer works!
Thank you, spent hours at this and this finally worked!
At the top of your Page(Located inside "Views" folder Default)
(AboutPage.xaml) is the starting one and the one i am using for this example.
Inside the <> of ContentPage, add Shell.NavBarIsVisible="False"
Example:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="YourNameHere.Views.AboutPage"
xmlns:vm="clr-namespace:YourNameHere.ViewModels"
Title="{Binding Title}"
Shell.NavBarIsVisible="False">
I'm learning Xamarin Forms. And specifically, if I want to share a complex link, but have the text be something simple how do you do that? What I have now is below.
await Share.RequestAsync(new ShareTextRequest
{
Uri = "thelink",
Title = "title", //ios doesn't use title
Text = "extra text"
});
That obviously just puts in the link and some text. But I want something more akin to an html hyperlink.
Well if you are asking how to put a hiperlink in Xamarin forms, you can do it like this, just create a class in the Portable project and then call it from your XAML page, but remember to read the Xamarin Essentials documentation cause you need to put this in you info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lyft</string>
<string>fb</string>
</array>
If you mean the Label with Hyperlinks , you can have a look at this doc here .
The text displayed by Label and Span instances can be turned into hyperlinks, sample code as follow :
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="Alternatively, click " />
<Span Text="here"
TextColor="Blue"
TextDecorations="Underline">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}"
CommandParameter="https://learn.microsoft.com/xamarin/" />
</Span.GestureRecognizers>
</Span>
<Span Text=" to view Xamarin documentation." />
</FormattedString>
</Label.FormattedText>
</Label>
When the hyperlink is tapped, the TapGestureRecognizer will respond by executing the ICommand defined by its Command property. In addition, the URL specified by the CommandParameter property will be passed to the ICommand as a parameter.
The code-behind for the XAML page contains the TapCommand implementation:
public partial class MainPage : ContentPage
{
// Launcher.OpenAsync is provided by Xamarin.Essentials.
public ICommand TapCommand => new Command<string>(async (url) => await Launcher.OpenAsync(url));
public MainPage()
{
InitializeComponent();
BindingContext = this;
}
}
The effect :
In addition , you also can create a reusable hyperlink class to make the xaml code more sample .
I have an <Entry> in xaml, and I want to get that value the user types.
<Entry x:name="enteredInput>
The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.
Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.
In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.
public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}
From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,
Navigation.PushAsync(new MainPage(enteredInput.Text);
I'm having a problem with showing Dialogs from a View Model. The problem is that the "underlying content is not dimmed and disabled" as the documentation says it should be. If I click on the underlying view the button in the dialog wired to the closed command is sometimes disabled and the user is not able to click it.
I defined the DialogHost in my MainView like this (also tried it in the ShellView):
<materialDesign:DialogHost
HorizontalAlignment="Center"
VerticalAlignment="Center"
CloseOnClickAway="True" />
From my MainViewModel I show the dialog like this:
Dim errView As New ErrorView
Dim res = Await DialogHost.Show(errView)
I wired up the close command on a button in the ErrorView dialog like this:
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
You problem is with the definition of DialogHost; you have it as an empty element.
The DialogHost is a ContentControl. Everything inside is what will become dimmed. So you define it at the root of your main Window/Page XAML, a bit more like:
<materialDesign:DialogHost CloseOnClickAway="True">
<StackPanel>
<TextBlock>Hello World</TextBlock>
<TextBlock>This is the main content of my application</TextBlock>
</StackPanel>
</materialDesign:DialogHost>
When using the FormsApplication base class with a brand new Xamarin.Forms app using Caliburn.Micro, I end up with an empty navigation bar at the top of my screen. I assume it's being created by Caliburn.Micro somehow, because an out-of-the-box Xamarin.Forms app doesn't have that.
Is there any way I can use Caliburn.Micro with Xamarin.Forms without this navigation bar?
I have not used Caliburn.Micro, but I am assuming that it is wrapping your page with a NavigationPage, as what you describe is what would happen if so.
You should be able to hide that navigation bar by setting a simple attribute in your page like so:
<ContentPage NavigationPage.HasNavigationBar="false"
..... >
</ContentPage>
If you are not using XAML pages and doing all of your UI in code instead, then you can do it this way within your page constructor:
NavigationPage.SetHasNavigationBar(this, false);
If you are using a Shell, (if you chose any of Visual Studios three Templates when first creating your project, you probably are) NavigationPage.HasNavigationBar="False" won't work. Try adding this line of code to each of your ContentPages
Shell.NavBarIsVisible="False"
This drove me nuts for a while as every answer I've seen for the code behind is a partial answer.
Lets say in your App.Xaml.cs file you have your NavigationPage constructor set like this:
MainPage = new NavigationPage(new Astronomy.MainPage());
You then have to go into the MainPage code behind and add code to remove the NavBar: you can't add the line to the app constructor.
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
So glad I finally figured this out! It's been causing me a headache for a while!
It works for me:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility =
(StatusBarVisibility)uiOptions;
}
If you are using Xamarin Forms 3.x try this in the constructor
SetValue(NavigationPage.HasNavigationBarProperty, false);
InitializeComponent();
After updating the MvvmCross nuget packages(to 8.0.2) and Xamarin Forms neget packages (to 5.0.0), I need to put this option explicitly.
put NavigationPage.HasNavigationBar="False" on your xaml ComtentPage
or MvxContentPage
New Here! My first comment
Just too confirm that "Cedric Moore"s Answer works!
Thank you, spent hours at this and this finally worked!
At the top of your Page(Located inside "Views" folder Default)
(AboutPage.xaml) is the starting one and the one i am using for this example.
Inside the <> of ContentPage, add Shell.NavBarIsVisible="False"
Example:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="YourNameHere.Views.AboutPage"
xmlns:vm="clr-namespace:YourNameHere.ViewModels"
Title="{Binding Title}"
Shell.NavBarIsVisible="False">