'Keyboard not hiding after push done or leave Entry
I am facing a problem with hiding the Keyboard after I am done using it or leave the Entry and touching the screen somewhere.
In Xamarin Forms, it is working normally, the Keyboard is hiding but in Maui it is not?
<CheckBox
x:Name="Cbbb1"
Grid.Row="1"
Grid.Column="0"/>
<Entry
x:Name="Ebb1"
Grid.Row="2"
Grid.Column="2"
Keyboard="Numeric" />
Remove Keyboard="Numeric" is not helping.
I am using VisualStudio 2022 preview Version 17.1.0 Preview 3.0.
I also tried this:
xmlns:local="clr-namespace:KeyboardhideMaui"
And this:
<Entry.Triggers>
<DataTrigger TargetType="Entry" >
<Trigger.EnterActions>
<local:FocusTriggerAction Focused="True" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<local:FocusTriggerAction Focused="False" />
</Trigger.ExitActions>
</DataTrigger>
</Entry.Triggers>
<CheckBox
x:Name="Cbbb1"
Grid.Row="1"
Grid.Column="0" />
<Entry
x:Name="Ebb1"
Grid.Row="2"
Grid.Column="2"
Keyboard="Numeric" />
Class
public class FocusTriggerAction : TriggerAction<Entry>
{
public bool Focused { get; set; }
protected override async void Invoke(Entry entry)
{
await Task.Delay(1000);
if (Focused)
{
entry.Focus();
}
else
{
entry.UnFocus();
}
}
}
I'm getting below error on entry.UnFocus();:
'Entry' does not contain a definition for 'UnFocus' and no accessible extension method 'UnFocus' accepting a first argument of type 'Entry' could be found (are you missing a using directive or an assembly reference?)
Solution 1:[1]
try this please :
Add this in your xaml page ( page resources )
<Style TargetType="Entry">
<Style.Triggers>
<EventTrigger Event="Unfocused">
<local:UnFocusTriggerAction />
</EventTrigger>
</Style.Triggers>
</Style>
then add UnFocusTriggerAction in your project
public class UnFocusTriggerAction : TriggerAction<Entry>
{
protected override void Invoke(Entry entry)
{
entry.Unfocus();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amjad S. |
