Gluon TextField Input Mask - gluon

How to put some input mask like '999.999.999-99' on Gluon TextField. I could build a new component inheriting from JavaFX TextField but I'd rather use Gluon TextField because it fits best on mobile.
I tried using StringConverter but it did not work.
Thanks!

The current Gluon Mobile TextFiled control does support floating text, max length count, and other features, but doesn't allow a TextFormatter directly.
If you have a look with ScenicView, the Gluon control is built upon a JavaFX TextField control.
While a text formatter is added to the control, using a lookup, you can get access to the internal JavaFX TextField and apply it.
If you are using a View created with FXML (Glisten-Afterburner template), that contains a Gluon Mobile TextField, you could just get the JavaFX one:
#FXML
private TextField gluonTextField;
public void initialize() {
gluonTextField.setFloatText("Insert phone number");
primary.setOnShown(e -> {
javafx.scene.control.TextField javafxTextField = (javafx.scene.control.TextField) primary.lookup(".text-input");
if (javafxTextField != null) {
javafxTextField.setTextFormatter(new TextFormatter<>(...));
}
}
}
See this question for a possible implementation of a TextFormatter for phone numbers.

Related

How to change shell flyout behavior of Android to be same as to IOS

The behavior of the navigation experience between flyout and detail pages is platform dependent:
On iOS, the detail page slides to the right as the flyout page slides
from the left, and the left part of the detail page is still visible.
On Android, the detail and flyout pages are overlaid on each other.
On UWP, the flyout page slides from the left over part of the detail
page, provided that the FlyoutLayoutBehavior property is set to
Popover. It it the deault behavior of different platform which we
could not change
I need a custom renderer for Xamarin Shell that changes the behaviour of Android to be similar to IOS one.
Uploaded sample code
public class CustomShellRenderer : ShellRenderer
{
public CustomShellRenderer(Context context) : base(context)
{
}
protected override IShellFlyoutContentRenderer CreateShellFlyoutContentRenderer()
{
//var flyoutContentRenderer = base.CreateShellFlyoutContentRenderer();
//var flyoutbackground = AppCompatResources.GetDrawable(Platform.CurrentActivity, Resource.Drawable.flyoutbackground);
if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.O)
{
//flyoutbackground.SetColorFilter(new BlendModeColorFilter(
// Shell.Current.FlyoutBackgroundColor.ToAndroid(), BlendMode.Color));
//flyoutContentRenderer.AndroidView.SetBackground(flyoutbackground);
}
else
{
//flyoutbackground.SetColorFilter(Shell.Current.FlyoutBackgroundColor.ToAndroid(), PorterDuff.Mode.Src);
//flyoutContentRenderer.AndroidView.SetBackgroundDrawable(flyoutbackground);
}
//return flyoutContentRenderer;
}
}
How the FlyoutPage manages the flyout and detail pages depends on whether the application is running on a phone or tablet, the orientation of the device, and the value of the FlyoutLayoutBehavior property. This property determines how the detail page will be displayed. It's possible values are:
Default – The pages are displayed using the platform default.
Popover – The detail page covers, or partially covers the flyout
page.
Split – The flyout page is displayed on the left and the detail page
is on the right.
SplitOnLandscape – A split screen is used when the device is in
landscape orientation.
SplitOnPortrait – A split screen is used when the device is in
portrait orientation.
The following XAML code example demonstrates how to set the FlyoutLayoutBehavior property on a FlyoutPage:
<FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FlyoutPageNavigation.MainPage"
FlyoutLayoutBehavior="Popover">
...
</FlyoutPage>
Note:
The value of the FlyoutLayoutBehavior property only affects applications running on tablets or the desktop. Applications running on phones always have the Popover behavior.
For more information, you can refer to document: Control the detail page layout behavior.

How can I replace the SearchBar icon in a Xamarin.Forms custom renderer for GTK?

I am working on a Xamarin project that includes a build for GTK. I am attempting to create a custom renderer for many of the Controls, but am having trouble finding, accessing and changing the properties for the control. For example, I would like to replace the "magnifying glass" icon for the SearchBar control with something more similar to the default icon on the Android platform.
I've created the custom renderer:
namespace MyProject.GTK.CustomRenderers
{
public class CustomSearchBarRenderer : Xamarin.Forms.Platform.GTK.Renderers.SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
var searchBar = Control;
// How do I replace the image?
}
}
}
but from there I am at a loss as there are practically no resources on custom renderers for GTK. I've tried looking at the GTK.Renderers.SearchBarRenderer to see if the class its derived from contains any useful properties or methods, as well as trying to find something meaningful in the GTK documentation and the repository for the Xamarin.Forms.GTK package, to no avail. I'm just not really sure how to understand the inner workings of the controls in this build so I can't figure out what I should even be looking for. Any pointers or resources for this or any GTK specific custom renderer work would be much appreciated.
You can check Xamarin Forms GTK
SearchBar is implmented by the use of element called SearchEntry which uses ImageButton and the icon is set by below code
_searchButton.ImageWidget.Pixbuf = RenderIcon("gtk-find", IconSize.SmallToolbar, null); // Search icon
Refer
SearchEntry.GTK
SearchBar.GTK
This should help you begin modifying, if you can get access to SearchEntry in your custom renderer you can change icon, otherwise you will have to create your own search bar, which takes lot of effort.

Is there an event name for this action?

Is there a ScrollView event in xamarin that is triggered when the user forces scroll up and scroll is already at top? Many apps uses this as the "command" to update the page.
Currently, there is no PullToRefresh property or RefreshCommand for a ScrollView built into Xamarin.Forms. However, It does exist on ListView as shown in the docs, which you might be able to use instead depending on your needs.
Also, it does look like there is a PullToRefreshLayout opensource project created by James Montemagno you might be able to use to easily implement pull to refresh with a ScrollView, but it has been a while since it's last been updated.
You can use the Scrolled event handler. If the ScrollView is already positioned at the top of the contents and the user "pulls down" then Y amount will be either 0 or negative (I know this will work on Android and iOS, not sure about UWP and others).
scroll.Scrolled += (object sender, ScrolledEventArgs e) =>
{
if (e.ScrollY <= 0)
{
// scrolled when already at top of list
}
};

Why would dragging a Xamarin scrollview not work when the mouse does work

I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.
When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.
I'm not sure even where to start troubleshooting.
I am targeting Windows 10. Other platforms optional at this point.
The structure of UI classes I have is this:
ContentPage.Content = StackLayout1
StackLayout1.Children = { StackLayout2, Scrollview }
StackLayout2 contains an entry field and two buttons
ScrollView, which is the problem, contains another StackLayout
Inside that I have some labels and some grids
Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.
public App() {
StackLayout sl = new StackLayout();
for (int i = 1; i < 20; i++) {
sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );
}
ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };
sv.Content = sl;
ContentPage cp = new ContentPage();
cp.Content = sv;
MainPage = cp;
}
Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?
There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)
This is the general method that interprets all the touch events from the whole screen.
As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.
So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.
The solution is to update Xamarin v2.0.0.6482, which came with my VS 2015 template, to v2.1.0.6529. Updating is a bit of a pain because of this problem https://bugzilla.xamarin.com/show_bug.cgi?id=39721. Once I got that installed scrolling started working with no other changes.
Scrolling is broken in the older version, on Windows, verified by a dev on the Xamarin forums.

Xamarin Forms Content Page: Change flow direction to Right to Left?

how can I change the flow direction of a Xamarin Forms Content Page from Left to Right to Right to Left? something like Windows Phone Flow Direction property?
#Hodor thanks, there is no support for such a thing (at least at this time). a workaround for this when using list views is to create multiple list item templates with LTR/RTL directions and use them accordin g to the current UI culture.
Another workaround for other controls is to implement a renderer for each control type and change its HorizontalOptions or XAlignment according to the UI culture.
it's 2017 and Xamarin forms does not support RTL yet..
It might be worth mentioning that the Grial UI Kit product has just added RTL support.
More details here
Try latest In latest Xamarin forms 3.0.0
If you’re making apps that support right-to-left languages, we have great news for you: Xamarin.Forms 3.0 makes it easier than ever to flip layouts to match language direction!
When supporting languages such as Arabic and Hebrew that flow right-to-left, you may now tap into the very easy to use FlowDirection property on any VisualElement instead of using platform-specifics or effects as you may have used previously. Because you already know the direction the device prefers by accessing Device.FlowDirection, updating your UI could be as easy as adding this to the head of your page in XAML:
FlowDirection="{x:Static Device.FlowDirection}"
For more information about updating your applications to support right-to-left layouts:
Right-To-Left Localization in Xamarin.Forms Blog
You mean the navigation flow?
Usually left => right means adding a page on the navigation stack and right => left means removing it.
You can extend a navigation controller on the "native" C# code and make custom animations. There are many ways to do that. Here's an example in MonoTouch
public partial class ScreenController : UINavigationController
{
private Page currentPage = null;
private void setCurrentPage(Page p)
{
currentPage = p;
//Using present View Controller: will set the current page to root.
PresentViewController(new UINavigationController(currentPage.CreateViewController())
{
ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal,
}, true, null);
//Using custom animation
PushControllerWithTransition(this, currentPage.CreateViewController(), UIViewAnimationOptions.TransitionFlipFromLeft);
}
public static void PushControllerWithTransition(this UINavigationController target, UIViewController controllerToPush,
UIViewAnimationOptions transition)
{
UIView.Transition(target.View, 0.75d, transition, delegate()
{
target.PushViewController(controllerToPush, false);
}, null);
}
}

Resources