This question already has answers here:
Xamarin forms navigation back button
(3 answers)
Closed 3 years ago.
How can I intercept the back button events in xamarin forms for Android and IOS and be able to show the user an alert to confirm the exit?
The objective is to intercept the 2 buttons, the navigation menu (yellow) and the device (orange)
I have seen some examples, but they are several years old.
I am using VS 2019 and the latest version of xamarin forms.
Thank you in advance for your help.
You can Use Title View instead of default navigation bar and handle the back button event. Please refer: https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/TitleView
also you can handle device back button event by override it like this:
protected override bool OnBackButtonPressed()
{
//return true to prevent back, return false to just do something before going back.
return true;
}
Hope this may resolve your issue.
Related
This question already has answers here:
Uwp navigation example and focusing on control
(2 answers)
Closed 6 years ago.
I have a Universal Windows Platform project that has a textBox element.
I'd like to set the focus to it when a Radio Button is clicked.
In the Radio Button click event, I can say:
txtBoxID.IsEnabled = true;
txtBoxID.Text = "";
But how do I set the focus? I saw some answers saying to use:
FocusManager.SetFocusedElement(
but my FocusManager class doesn't have that method.
edit: Solved, thanks. Just needed to know what argument to pass to SetFocus. The other fellow's question which was thought to be similar was regarding an event occurring after he set focus to his control.
All the code you need is:
txtBoxID.Focus(FocusState.Programmatic);
Method is defined in Control.
I have a scrollView with a Grid inside which contains several Entrys.
When I click anywhere on the screen that isn't one of the Entry controls the focus automatically goes to the first Entry I have on the grid. I.e. This happens whether any Entry already has Focus or not, it will always set the focus of the first one again.
If I remove the Scrollview and have the Grid on screen on it's own I don't get this issue.
I am developing an application for a Windows 10 device but using the Xamarin forms cross platform code as we may move the code to Android at some stage.
Thanks in advance.
I was able to reproduce the described behavior on UWP Windows 10, but not on Android or iOS, so this is a bug in the Forms code for UWP.
I have filed a bug report for this issue which you can track here: https://bugzilla.xamarin.com/show_bug.cgi?id=52613
Xamarin engineers will now discuss this issue on the bug report. If you would like to receive a notification when the bug is updated, you can add yourself to the CC list for the bug. Please note that you will need to create an account on that system if you have not already done so.
I don't know if you solved your problem because it was more than a year ago and the issue #jgoldberger has opened on Xamarin's Bugzilla did not progress since last October.
Nevertheless I just noticed the same behaviour on my UWP app and after looking around the internet I found a solution.
If you look at this thread : Why does my TextBox get focused when clicking inside of ScrollViewer?
Then it is easy to imagine a solution for a Xamarin.Forms app by creating a custom renderer inside your UWP project.
You can use the following code which is working perfect for me :)
using {your_project_namespace}.UWP;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewCustomRenderer))]
namespace {your_project_namespace}.UWP
{
public class ScrollViewCustomRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Control.IsTabStop = true;
}
}
}
Hope this helps.
Cheers
This question already has answers here:
Remove the title bar in Windows Forms
(7 answers)
Closed 9 years ago.
I am actually developing a UserControl that requires this kind of form.
Normally a WinForms Form looks like this:
If I set "FormBorderStyle = None", it looks like this:
But, I actually need a window without TitleBar like the following:
Please see the difference at the edge of the window. It actually looks more like a context menu.
myForm.Text="";
myForm.ControlBox= false;
This solution leaves the TitleBar so that the form remains movable. This is a problem.
I actually need this: the user click the button and the form appears like the following:
How to do this?
you can use:
yourForm.Text="";
yourForm.ControlBox= false;
and in properties, change : FormBorderStyle to :FixedDialog
To get like that then do not set any title text and make controlbox visible false
like this
yourForm.Text="";
yourForm.ControlBox= false;
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I remove the selection border on a ListViewItem
I'm using the following code to make a Listview to use windows 7 native look and to prevent flickering.
Windows 7 Native Look for .NET ListView
http://geekswithblogs.net/CPound/archive/2006/02/27/70834.aspx
But I'm still getting a black dotted selection rectangle.
The question will be... How can I achieve the explorer selection rectangle?
Thank you so much for your help.
Based on the comment in the link provided by AVIDeveloper.
While the ShowFocusCues itself didn't work, the WM_CHANGEUISTATE
listed on that MSDN page led me to the right answer. By sending a
WM_CHANGEUISTATE message with UISF_HIDEFOCUS I was able to get rid of
the focus rectangle. – Telanor Apr 22 '10 at 17:11
I tried to find some information about this messages and eventualy saw this post: http://cboard.cprogramming.com/csharp-programming/128345-listview-remove-focuscues.html#post958690
So, we need to send the WM_CHANGEUISTATE message to the ListView in the constructor
SendMessage(Handle, 0x127, 0x10001, 0);
And we are only going to override the OnSelectedIndexChanged and OnEnter events.
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
Without overriding the OnEnter event, the same black dotted selection rectangle will appear when the ListView gets the focus.
I tried to explain the best I could since I'm not a fluent English speaker and I'm going to wait if someone has a better answer before accepting mine.
I saw method to do this for current control but I need to do it for all app. I have touch scren and when i click on some textbox virtual keyboard from windows 7 shown. I don't need it because i how own keyboard in program.
Please help.
Thanks.
Not sure if you got an answer in the few months the question was online, but this worked for me.
First, you need a reference to Microsoft.Ink.dll.
var handle = new WindowInteropHelper(this).Handle;
TextInputPanel panel = new TextInputPanel(handle);
panel.InPlaceVisibleOnFocus = false;
That first line gets a Handle to the window of your app, and then you just need to create the TextInputPanel object and set it's InPlaceVisibleFocus to false. This will no longer show the TIP icon when a textbox is touched.