I've just started to test my app on android tablet and have found a strange bug:
I wanted to being masterpage enabled only when my main page is opened.
So I created Custom NavigationPage and overrided methods:
/// <summary>
/// Отключение бокового меню при добавлении на главный экран новых страниц
/// </summary>
/// <param name="child"></param>
protected override void OnChildAdded(Element child)
{
base.OnChildAdded(child);
if (this.Navigation.NavigationStack.Count > 1)
App.detailPage.IsGestureEnabled = false;
}
/// <summary>
/// Включение бокового меню при наличии только одной страницы на главном экране
/// </summary>
/// <param name="child"></param>
protected override void OnChildRemoved(Element child)
{
base.OnChildRemoved(child);
if (this.Navigation.NavigationStack.Count < 2)
App.detailPage.IsGestureEnabled = true;
}
here is my landscape main page:
When I push some pages to my NavigationPage, the master page disappears:
and after that, when I return on my main page, the masterpage is still not available:
At least I need to show my MasterPage on my MainPage, and it would be perfect if somebody tell me, how to hide masterpage to the left and use it with swipe gestures, like on phones. Thanks in advance.
By the way, I've found the answer for my issue :)
Right now, I end up with adding behavior for Tablet idiom in my MasterPage.
Constructor's code:
public MasterDetailPage1()
{
InitializeComponent();
/// Some coding
if (Device.Idiom == TargetIdiom.Tablet)
MasterBehavior = MasterBehavior.Popover;
/// Some coding
}
Hope that helps somebody.
Related
Related to: YouTube iframe embed - full screen
Is it possible to pass the allowFullscreen without iframe? I'm developing for Xamarin and I'm using a WebView that simply opens the embed url itself, I don't see the need for iframe here, but I'd like to have the fullscreen possibility...
To enable full-screen support in a Xamarin Forms WebView for Android, you can create custom fullScreen_webview to do.
public class FullScreenEnabledWebView : WebView
{
/// <summary>
/// Bindable property for <see cref="EnterFullScreenCommand"/>.
/// </summary>
public static readonly BindableProperty EnterFullScreenCommandProperty =
BindableProperty.Create(
nameof(EnterFullScreenCommand),
typeof(ICommand),
typeof(FullScreenEnabledWebView),
defaultValue: new Command(async (view) => await DefaultEnterAsync((View)view)));
/// <summary>
/// Bindable property for <see cref="ExitFullScreenCommand"/>.
/// </summary>
public static readonly BindableProperty ExitFullScreenCommandProperty =
BindableProperty.Create(
nameof(ExitFullScreenCommand),
typeof(ICommand),
typeof(FullScreenEnabledWebView),
defaultValue: new Command(async (view) => await DefaultExitAsync()));
/// <summary>
/// Gets or sets the command executed when the web view content requests entering full-screen.
/// The command is passed a <see cref="View"/> containing the content to display.
/// The default command displays the content as a modal page.
/// </summary>
public ICommand EnterFullScreenCommand
{
get => (ICommand)GetValue(EnterFullScreenCommandProperty);
set => SetValue(EnterFullScreenCommandProperty, value);
}
/// <summary>
/// Gets or sets the command executed when the web view content requests exiting full-screen.
/// The command is passed no parameters.
/// The default command pops a modal page off the navigation stack.
/// </summary>
public ICommand ExitFullScreenCommand
{
get => (ICommand)GetValue(ExitFullScreenCommandProperty);
set => SetValue(ExitFullScreenCommandProperty, value);
}
private static async Task DefaultEnterAsync(View view)
{
var page = new ContentPage
{
Content = view
};
await Application.Current.MainPage.Navigation.PushModalAsync(page);
}
private static async Task DefaultExitAsync()
{
await Application.Current.MainPage.Navigation.PopModalAsync();
}
}
More detailed info about enable full-screen support in xamarin.android Webview, you can take a look this sample:
https://github.com/microsoft/CSSClientAppsXamarinSampleCode/tree/main/FullScreenWebView
You can click Iframe in the red box at the bottom right to full-screen, the screenshot:
I'm just about to start to get into Xamarin to create a Windows Mobile App. I'm using Visual Studios 2019 and created an empty Mobile App. For the beginning I used a Youtube Tutorial to create a simple calculator (https://www.youtube.com/watch?v=yCRxbnwORIM&t=967s). In the designer everything is displayed as I want it. Just when I try to start the emulator it doesn't show up the elements I created. It still shows the standard text "Welcome to Xamarin.Forms!".
In the MainPage.xaml I basically just designed some basic elements as the Headline and Textboxes:
<forms:WindowsPage
x:Class="Taschenrechner.UWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:forms="using:Xamarin.Forms.Platform.UWP"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Taschenrechner.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="titleTextblock" FontSize="38" RelativePanel.AlignHorizontalCenterWithPanel="True" Margin="0,12">Taschenrechner</TextBlock>
<RelativePanel RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.Below="titleTextblock">
<TextBlock x:Name="firstNumberTextblock" Margin="0,6,12,0">Zahl 1:</TextBlock>
<TextBox x:Name="firstNumberTextbox" RelativePanel.RightOf="firstNumberTextblock" Width="250" Margin="0,0,0,8"></TextBox>
<TextBlock x:Name="secondNumberTextblock" Margin="0,6,12,0" RelativePanel.Below="firstNumberTextbox">Zahl 2:</TextBlock>
<TextBox x:Name="secondNumberTextbox" RelativePanel.AlignLeftWith="firstNumberTextbox" Width="250" RelativePanel.Below="firstNumberTextbox"></TextBox>
<Button x:Name="Addition" RelativePanel.RightOf="firstNumberTextbox" Margin="12,0,0,0" Width="30">+</Button>
<Button x:Name="Subtraktion" RelativePanel.RightOf="Addition" Margin="12,0,0,0" Width="30">-</Button>
<Button x:Name="Multiplikation" RelativePanel.Below="Addition" RelativePanel.RightOf="secondNumberTextbox" Margin="12,6,0,0" Width="30">*</Button>
<Button x:Name="Division" RelativePanel.Below="Addition" RelativePanel.RightOf="Multiplikation" Margin="12,6,0,0" Width="30">*</Button>
<TextBlock x:Name="Ergebnis" RelativePanel.Below="secondNumberTextbox" RelativePanel.AlignLeftWith="secondNumberTextbox" Margin="52,12,0,0" FontSize="24">Ergebnis:</TextBlock>
<TextBlock x:Name="Wert" RelativePanel.RightOf="Ergebnis" RelativePanel.Below="secondNumberTextbox" Margin="12,12,0,0" FontSize="24">0</TextBlock>
</RelativePanel>
Screenshot MainPage.xaml
Screenshot Emulator
I didn't change anything in the MainPage.xaml.cs so far.
Following the App.xaml.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Taschenrechner.UWP
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
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();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
Link to the project:
https://www.dropbox.com/sh/y2aihos2mht5122/AACjRODrXPARSEanjJYrPaTva?dl=0
I don't receive any error Messages or Warnings. Can you help me what I have to change so the emulator runs probably?
From shared sample project, I got the reason. Your created project is a Forms Application.
Every time , the application launched to this MainPage.xaml in Froms ,not in Universal Windows .
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Taschenrechner.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
If you want to enter Universal Windows MainPage.xaml ,forms app need to use Custom Renderer .
However , if only want to create a UWP app, when creating new project , you should choose as follow:
And the structure of project should be follow, then adding Xaml code in MainPage.xaml can be your want.
I have AVPlayer and when i move to next page, player continues playing and if i add observers they crash if i don't dispose them but i am unable to find a way to handle dispose because ContentView doesn't tell you when it is in background.
Please help ?
In Xamarin Forms there is no way for a ContentView to find out when it's hosting page is disappearing, unless it gets some help from the Page itself. So how I've achieved this previously is as follows:
Step 1) Define an OnDisappearing Method in your ContentView
In your ContentView define a method called OnDisappearing and inside it, do whatever you need to when the view disappears - in your case it sounds like you need to remove your observers and dispose your player. So it would look something like this:
public void OnDisappearing()
{
_playerPositionChangedObserver?.Dispose();
_player?.Dispose();
}
Defining this method in itself won't do anything, you need to actually call it from somewhere - that's where the page comes in...
Step 2) Override the OnDisappearing method in your page
The page will be told when it's appearing or disappearing and you can use that to then forward on to your other ContentView. In the example below MyPage is overriding the OnDisappearing method and then calling that method that I defined on my ContentView in step 1.
public class MyPage : ContentPage
{
public MyPage()
{
InitializeComponent();
}
/// <summary>
/// Performs page clean-up.
/// </summary>
protected override void OnDisappearing()
{
base.OnDisappearing();
contentView.OnDisappearing();
}
}
I need to Hide the overflow icon in Hardware menu button in my Xamarin Android app(three dots) - refer the screen shot.
How do i do this?
I did not find the overflow icon in my nexus 6, but I would like give you some suggestions:
For the xamarin android project the Android.App.Activity is different between the Activity of Java android.
We can find the source code of the Android.App.Activity when the activity create a menu it will call the following function:
// Summary:
// Initialize the contents of the Activity's standard options menu.
//
// Parameters:
// menu:
// The options menu in which you place your items.
//
// Returns:
// To be added.
//
// Remarks:
// ///
// Initialize the contents of the Activity's standard options menu. You /// should
// place your menu items in to menu. /// ///
// ///
// This is only called once, the first time the options menu is /// displayed. To
// update the menu every time it is displayed, see /// Android.App.Activity.OnPrepareOptionsMenu(Android.Views.IMenu).
// /// ///
// ///
// The default implementation populates the menu with standard system /// menu items.
// These are placed in the Android.Views.Menu.CATEGORY_SYSTEM group so that ///
// they will be correctly ordered with application-defined menu items. /// Deriving
// classes should always call through to the base implementation. /// ///
// ///
// You can safely hold on to menu (and any items created /// from it), making modifications
// to it as desired, until the next /// time onCreateOptionsMenu() is called. ///
// ///
// ///
// When you add items to the menu, you can implement the Activity's /// Android.App.Activity.OnOptionsItemSelected(Android.Views.IMenuItem)
// method to handle them there.
// ///
// /// /// [Android Documentation] /// ///
// ///
[Register("onCreateOptionsMenu", "(Landroid/view/Menu;)Z", "GetOnCreateOptionsMenu_Landroid_view_Menu_Handler")]
public virtual bool OnCreateOptionsMenu(IMenu menu);
This onCreateOptionsMenu function will be called as default. Xamarin android encapsulates onCreateOptionsMenu function of Java Android. I think you can override the function in you MainActivity as follows:
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu)
{
return false;
}
}
The menu should be created as default.
That depends on a Particular Device and Its OS , some of them create options menu like your device but some on right corner of the top
We're working on a desktop WPF app that runs on Windows 7 tablets and are adding some Surface Pro units with windows 8 to the mix.
We noticed immediately that the little keyboard icon no longer displays when a TextBox receives focus. We solved it by running "tabtip.exe" on the MouseDown event for all TextBoxes.
We have some numeric textboxes though (quantity for an item on an order), and want to open the on-screen keyboard for numeric entry, but it opens with qwerty keys by default.
I have been searching extensively for any command-line arguments I can pass to tabtip.exe to change its input mode, but have had no luck. This seems like a trivial task with a metro-style app, but impossible on the desktop side.
Is there a command-line argument to tabtip.exe I can use to accomplish this?
Following on from the answer #tymes provided, here is a quick console app which demonstrates opening the keyboard and changing various settings (C#).:
using System;
using System.Diagnostics;
using Microsoft.Win32;
namespace CSharpTesting
{
class Program
{
/// <summary>
/// The different layout types on the virtual keyboard.
/// </summary>
public enum KeyboardLayoutMode
{
Default,
ThumbLayout,
Handwriting
}
/// <summary>
/// The registry key which holds the keyboard settings.
/// </summary>
private static readonly RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\TabletTip\\1.7");
static void Main(string[] args)
{
SetKeyboardDockedMode(true);
SetKeyboardLayoutMode(KeyboardLayoutMode.ThumbLayout);
ShowKeyboard(true);
}
/// <summary>
/// Shows the onscreen keyboard.
/// </summary>
/// <param name="killExistingProcess">If true, kill any existing TabTip.exe process.</param>
public static void ShowKeyboard(bool killExistingProcess)
{
if (killExistingProcess)
{
// If the user presses the close button on the keyboard then TabTip.exe will still run in the background. If we have made registry
// changes to the keyboard settings, they don't take effect until the process is started again so killing this ensures the keyboard
// will open with our new settings.
foreach (var process in Process.GetProcessesByName("TabTip"))
{
process.Kill();
}
}
string onScreenKeyboardPath = #"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
Process.Start(onScreenKeyboardPath);
}
/// <summary>
/// Sets if the keyboard is in docked or floating mode.
/// </summary>
/// <param name="isDocked">If true set to docked, if false set to floating.</param>
private static void SetKeyboardDockedMode(bool isDocked)
{
registryKey.SetValue("EdgeTargetDockedState", Convert.ToInt32(isDocked), RegistryValueKind.DWord);
}
/// <summary>
/// Changes the layout mode of the keyboard.
/// </summary>
/// <param name="mode">The layout mode to use.</param>
private static void SetKeyboardLayoutMode(KeyboardLayoutMode mode)
{
switch (mode)
{
case KeyboardLayoutMode.Handwriting:
registryKey.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord);
registryKey.SetValue("LastUsedModalityWasHandwriting", 1, RegistryValueKind.DWord);
break;
case KeyboardLayoutMode.ThumbLayout:
registryKey.SetValue("KeyboardLayoutPreference", 1, RegistryValueKind.DWord);
registryKey.SetValue("LastUsedModalityWasHandwriting", 0, RegistryValueKind.DWord);
// 0 = small, 1 = medium, 2 = large
registryKey.SetValue("ThumbKeyboardSizePreference", 2, RegistryValueKind.DWord);
break;
default:
registryKey.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord);
registryKey.SetValue("LastUsedModalityWasHandwriting", 0, RegistryValueKind.DWord);
break;
}
}
}
}
in HKEY_CURRENT_USER\Software\Microsoft\TabletTip\1.7 (Windows 8)
change the REG_DWORD KeyboardLayoutPreference
value of 0 is the regular layout
value of 1 is the split keyboard with the numberpad in the middle
the REG_DWORD LastUsedModalityWasHandwriting also has to be 0 or if 1, when tabtip is started again it will open with the pen handwriting area.
You may control input mode by registry setting for Tabtip. Look for the registry entry with name KeyboardLayoutPreference.
I've never used win 8 but in win 10 you can use InputScope to control what on-screen keyboard is used:
<TextBox Grid.Row="0"
InputScope="Number" />
<TextBox Grid.Row="1"
InputScope="Default" />