I have a requirement where a field in a Xamarin Forms app is allowed to have only numbers, spaces and dashes. Numeric keyboard layout appears to be perfect for this purpose - the only trouble - the space and dash buttons do not appear to work? Is there any way to enable these, specifically on Android - as that is the primary target platform.
Buttons in question are highlighted.
<Entry
x:Name="BarcodeEntry"
Margin="12,0"
HeightRequest="40"
Placeholder="Barcode"
Style="{StaticResource BorderlessEntryStyle}"
Keyboard="Numeric"
Text="{Binding Barcode.Value, Mode=TwoWay}">
Control is bound to this property:
private string _barcode;
public string Barcode
{
get => _barcode;
set { SetProperty(ref _barcode, value); }
For the numberic keyboard, we only have four related InputTypes.
number: A numeric only field.
numberDecimal: Can be combined with number and its other options to allow a decimal (fractional) number.
numberPassword: A numeric password field.
numberSigned: Can be combined with number and its other options to allow a signed number.
For more details about the InputTypes, you could refer to the link below. https://developer.android.com/reference/android/widget/TextView#attr_android:inputType
If you want to use the space and dash buttons, you could use the Telephone keyboard. Or you could create your own custom keyboard.
Custom Keyboard: Numeric keyboard as default on Xamarin.Forms, but allow text (cross platform)
Related
I want to remove the up and down arrow when using the MUI number field. I'm using version 5.3.0. Is it possible in sx prop?
The sx prop
<TextField
sx={{...}}
id="outlined-number"
label="Number"
type="number"
/>
From the docs, the type prop accepts valid HTML input types. I believe the reason the up and down arrows are present is because you specified number as the type.
Try type="tel" instead, as it seems to be the standard input type for phone numbers.
Here is a reference to the tel type and why it's a good idea to use it. Note that if the current browser doesn't support it, it will fall back to being a regular text field
I found this answer here:
How to remove the up and down arrow from a mui number field?
I am using Editor control and wish to wrap long messages (Like Whatsapp).
I have explored few sites and got nothing . If this feature is not yet in Xamarin Forms , can I know any alternative for the same ?
My XAML
<Editor Grid.Row="0" Grid.Column="0" Text="{Binding TextMessage}"
TextColor="{StaticResource StartColor}" HorizontalOptions="FillAndExpand"
FontSize="14" TextChanged="Editor_TextChanged"
FontFamily="{StaticResource DefaultFont}" IsEnabled="True"/>
OUTPUT-
I would first suggest you to use AutoSize property of Editor, so if you want your editor to automatically resize depending on the text length, you should set it to TextChanges, otherwise set it to Disabled(this is default value).
Next thing, if you know that the Editor will be used for chat, you can also set Keyboard property to Chat:
<Editor Text="Enter text here" AutoSize="TextChanges" Keyboard="Chat" />
If I am not mistaken, The Editor control has a property for this called the AutoSize Property which takes the EditorAutoSizeOption enum as an input. Available options are TextChanges and Disabled.
<Editor AutoSize="TextChanges"...
If for some reason this does not work for you then you can use the solution in this forum discussion. by ionixjunior.
For those who are still facing issues, I have a case where the line does not wrap as long as there is no break line (Enter). Solution was to change parent layout from StackLayout to Grid. With grid, now it works.
If you want the height to change dynamically when you have more lines, you can use the above solution:
AutoSize="TextChanges"
Can any one Please provide Numeric UpDown Control demo with Xamarin Forms
Does this control Available in Xamarin Forms?
thanks
Prashanth
See edit #2.
No there is not a spinner control out-of-the-box. If you do not want to get creative, you could use the Picker control and insert predefined values into it. Picker info here.
Otherwise it would be pretty trivial to create an up and down Button and an Entry or Label. Clicking the up Button increments a number in the Entry or Label. Clicking the down Button decrements a number in the Entry or Label.
*Edit: Just happened to land on Syncfusion's NumericUpDown control which does want you want. You can also get a free community license for the control if you are a lone developer or a group of 5 or fewer people. Community License info here
*Edit #2: Was looking through the Xamarin Views list page here and saw that actually do have a Stepper control now!
You can use Stepper for this:
XAML
<Stepper Value="5"
Minimum="0"
Maximum="10"
Increment="0.1"
HorizontalOptions="LayoutOptions.Center"
VerticalOptions="LayoutOptions.CenterAndExpand"
ValueChanged="OnValueChanged" />
C#
void OnValueChanged(object sender, ValueChangedEventArgs e) {
lbldisp.Text = String.Format("Stepper value is {0:F1}", e.NewValue);
}
https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.stepper?view=xamarin-forms
maybe this could help. you might want to write a custom render for putting that textBox in between the -/+ buttons but sure if you can use as it is, it works fine.
I'm developing a RCP application, where I need to assign shortcut (Alt+[key]) to SWT Button with image.
I'm able to assign shortcut to Button with text using "&" character,
fox ex: button.setText("&Select All"); then Alt+S will act as shortcut fot that button.
I have 2 questions regarding this:
How to assign Alt+[key] shortcut to SWT button with images (no text), without using key listener?
How to assign Alt+[key] shortcut to SWT button with text, but no shortcut key letter in that text, again without using key listener.
for ex: "UnFix" is the text on button and shortcut key should be Alt+Q.
I hope there should be a way to do this in SWT.
You can select a mnemonic by placing an ampersand before the letter that should serve as the mnemonic letter (like "&Select All").
If the control does not have a text or the desired letter does not occur in that text, you will ned to use key event listener. There is no way around that.
Some applications work around the 'missing letter' in that they place the mnemonic letter in brackes like this: "UnFix (&Q)". Though this technically work, I find this an esthetically rather unfortunate choice.
Using an unobvious mnemonic letter has also usability issues: how would a user ever know or memorize that Alt+Q means 'UnFix'?
After trying lots of work arounds, I'm finally able to assign shortcut key to SWT button with image.
SWT Button.class make use of getText() method to find mnemonic, so overring getText() method of Button.class and returing mnemonic key will serve the purpose. checkSubclass() method should also be overridden to do nothing otherwise swt's Subclassing not allowed error will occure.
Button newButton = new Button(parent, SWT.PUSH){
#Override
public String getText() {
return "&N";
}
#Override
protected void checkSubclass() {
// Do Nothing to avoid Subclassing Not Allowed error.
}
};
newButton.setImage(newButtonImage);
I above example newButton has the shortcut key Alt+N.
In my Flex 3 application the user enters IP addresses into a textInput object.
As the user enters the numbers comprising the ip address I would like to add the '.' on the fly rather than waiting until latter, so that if the user types 127000000001 I would like the textInput control to display 127.000.000.001.
I've been trying to make a class that extends textInput and adds the '.'s to the object's text property in the Event.CHANGE or Event.TextInput handler.
Sadly, my extra '.' never gets displayed, the numbers appear without dots just as the user typed them.
Any suggestions as to how to extend textInput to display numbers in the IP dot notation?
A better bet might be to use the YAHOO! Astra Flex Components library, which contains a custom component for this very purpose.
Have you tried overriding the component, and it's "text" setter function? That should work.
override public function set text(value:String):void {
super.text = <value formatted as IP address>
}