:::: MENU ::::

Tuesday, November 20, 2018

Actually this can be done very easily with the Screen class. 
Here is a small sample that display a second form, full screen, on your second monitor if there is one. 

Note: The code is to be put in your main Form class.

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (Screen.AllScreens.Length > 1)
{

Form2 frm = new Form2();

// Important !
frm.StartPosition = FormStartPosition.Manual;

// Get the second monitor screen
Screen screen = GetSecondaryScreen();

// set the location to the top left of the second screen
frm.Location = screen.WorkingArea.Location;

// set it fullscreen
frm.Size = new Size(screen.WorkingArea.Width, screen.WorkingArea.Height);

// Show the form
frm.Show();

}
}

public Screen GetSecondaryScreen()
{
if (Screen.AllScreens.Length == 1)
{
return null;
}

foreach (Screen screen in Screen.AllScreens)
{
if (screen.Primary == false)
{
return screen;
}
}

return null;
}

Sunday, November 18, 2018

'Done' button on Numeric keyboard on iOS is a very popular clients request, but it does not appear out of the box. Luckily the solution is very easy (as usual), all we have to do is to extend 'Entry' control and to add a custom renderer:
 
using Xamarin.Forms;
namespace YourNamespace.Controls
{
public class ExtendedEntry : Entry { }
}
view rawExtendedEntry.cs hosted with ❤ by GitHub
/*
Based on example from: https://forums.xamarin.com/discussion/18346/add-done-button-to-keyboard-on-ios
*/
using System.Drawing;
using YourNamespace.Controls;
using YourNamespace.iOS.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedEntry), typeof(ExtendedEntryRenderer))]
namespace YourNamespace.iOS.Renderers
{
public class ExtendedEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Element == null)
return;
// Check only for Numeric keyboard
if (this.Element.Keyboard == Keyboard.Numeric)
this.AddDoneButton();
}
/// <summary>
/// <para>Add toolbar with Done button</para>
/// </summary>
protected void AddDoneButton()
{
var toolbar = new UIToolbar(new RectangleF(0.0f, 0.0f, 50.0f, 44.0f));
var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate
{
this.Control.ResignFirstResponder();
var baseEntry = this.Element.GetType();
((IEntryController)Element).SendCompleted();
});
toolbar.Items = new UIBarButtonItem[] {
new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace),
doneButton
};
this.Control.InputAccessoryView = toolbar;
}
}
}
As you can see all the 'magic' is happing in AddDoneButton() method. We create a toolbar and add a 'Done' UIBarButtonItem which will hide the keyboard and send a 'Completed' event back.
The solution is based on this thread and available as a gist on github.

Wednesday, November 14, 2018