Xamarin.Forms Entry Focus when Unfocused - xamarin

I need it so that when the Entry loses focus, the focus returns to the Entry (therefore locking the focus on an Entry).
I did the following code:
myEntry.Unfocused += (object sender, FocusEventArgs e) => {
if (!e.IsFocused)
{
((Entry)sender).Focus();
}
};
It works, but the keyboard stops working - I can't write anything.
Is this a bug? Can someone help me?

I found that this is a bug xamarin.forms 2.0.0.0. Updated and solved the problem.

I know on android if you click on an Entry and give it focus, the keyboard will appear, and then if you click another element, the Entry will lose focus and the keyboard will go away. So by refocussing on the Entry when it loses focus, you might be forcing the keyboard to be minimized. This is a total guess though.
What you might be able to do is set the most parent element's InputTransparent property to true and then only set the Entry.InputTransparent property to false so that the user is unable to click anything but the Entry.
If that does not work, then you could also try adding a transparent ContentView that covers everything except the Entry and set the ContentView.InputTransparent to true which would have the same effect.

Related

Android: Add Custom keyboard to Xamarin.Forms

I am working on a Xamarin Forms project.
We are testing a Android Device running KitKat that has a 12 key keyboard.
I am trying to force the softinput keyboard from showing when focus is given to an Entry for which I created a custom Renderer which overrides the FocusChange and Clicked events.
It kinda works as I detect if the device has a physical keyboard and if the entryKeyboard is numeric. If both those conditions are true, I call
Control.ShowSoftInputOnFocus = false;
AND
imm.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);
It mostly works, except when the view containing the Entry editor opens. the keyboard is shown for a few moments and then it disappears. That's a problem on 2 fronts. It moves up the buttons that end up at the bottom of the view while the keyboard is measured, so buttons appear, move up and then back down when keyboard ultimately disappears. Second, once in a while it doesn't work. We have put a few delays, but that only compounds the problem since the keyboard ends up on screen longer.
In a perfect world, I don't care about the delays, I just don't want the softInput to show up anywhere in this view unless I specifically ask for it,
Alternately, I would not mind writing my own invisible keyboard and have to show (invisibly) while the async process is performing.
I have been searching everywhere for a while, so any help would be greatly appreciated.
thanks in advance and have a nice day
I think you need to make a custom renderer for your EditText's. Then also create your own implementation of EditText which overrides the OnCheckIsTextEditor method, which simply returns false.
If you are only targeting Android API 21 and up, you can alternatively just call ShowSoftInputOnFocus = false on all your EditText instances. This could probably be done with an Effect in Xamarin.Forms.

How to show a dialog from another dialog?

I am newbie to MFC. I have a native C++ MFC app. I want to show a dialog from main dialog. In the main dialog I am having three button (Back, Next, Cancel) respectively.
On the Next button click event I am calling DoModal to show another dialog by hiding the main dialog as follows,
void CFirstPage::OnBnNextButton()
{
::ShowWindow(this->GetSafeHwnd(),SW_HIDE);
CSecondPage secondDlg;
secondDlg.DoModal();
}
void CSecondPage::OnBnBackBtnClicked()
{
::ShowWindow(this->GetSafeHwnd(),SW_HIDE);
CFirstPage FirstPage;
FirstPage.DoModal();
}
After executing this code snippet, the main dialog got hidden and even the application icon also disappears from the taskbar and again appears when the other dialog pops up.
(Basically I am having the same icon for both the dialogs, the icon should not get disappeared and appear again. It has to remain same without appearing and disappearing .)
How can show the icon in the taskbar without any flickering effect?
During traversing from back to next in middle I clicked cancel and the Cancel event is handled as follows,
void CFirstPage::OnCancel()
{
CDialog::EndDialog(TRUE);//For closing the dialog.
}
void CSecondPage::OnCancel()
{
CDialog::EndDialog(TRUE);//For closing the dialog.
}
Steps1:Click Next in the main dialog
Step2: Click Cancel in the second page
Now the application closes. But still instance is active in the "TaskManager". As per my understanding no instance should be alive once windows is closed ?
I suspect as the first dialog is only hidden not ended that instance is still existing in the TaskManager. Is this understanding correct?
How can I resolve this issue?
Can anyone kindly help me to resolve this issue.
As said by Iinspectable property sheets are best suited for your your problem statement.A very good example on how to use CPropertysheets can be found in codeproject
CProperty sheet example
Probably your main windows is still hidden after you end dialog with second page. Ending dialog of CSecondPage does not close application only closes active CSecondPage dialog.
Also OnCancel/OnOK does not need to be overriden if you just EndDialog with it. There is default behaviour implemented in OnCancel, which will close the dialog.
After secondPage.DoModal() show your main dialog again, or close it if that is the behaviour you want to achieve.
FirstPage isn't the original first dialog now, so you should store the first dialog object by yourself. You can do that like this:
void CFirstPage::OnBnNextButton()
{
::ShowWindow(this->GetSafeHwnd(),SW_HIDE);
CSecondPage secondDlg;
secondDlg.setFirstDialog(this); //customer function to store first dialig object
secondDlg.DoModal();
}
void CSecondPage::OnBnBackBtnClicked()
{
::ShowWindow(this->GetSafeHwnd(),SW_HIDE);
::ShowWindow(m_firstDialog->GetSafeHwnd(), SW_SHOW);
}

wxWidgets event focus textcontrol

I have another wxWidgets question regarding events and focus.
I have already looked at the tutorials and this old question here but I am still running into problems C++ Event (Focus) Handling
Basically I have a dialog with two wxTextCtrl elements and a Button.
What I would like to achieve is, that when I click on button it needs to tell me which of the two elements previously had the focus.
In the constructor of my Dialog I created all the elements and then connected them to the eventhandler like this: Ttop->Connect(TOP,wxEVT_KILL_FOCUS,(wxObjectEventFunction)&UI_ADDENTRY::hasfocus);
Tbottom->Connect(BOTTOM,wxEVT_KILL_FOCUS,(wxObjectEventFunction)&UI_ADDENTRY::hasfocus);
then there is the eventhandler that safes the id into focus
void UI_ADDENTRY::hasfocus(wxFocusEvent& event){
focus= event.GetId();
event.Skip();}
however when i try to access focus in the Button function it always tells me: 0 instead of TOP or BOTTOM / the ids that I gave the textcontrols
void UI_ADDENTRY::OnRecord(wxCommandEvent &event){
wxString tmp;
tmp << this->focus;
wxMessageBox(tmp);}
What am I doing wrong? is there another way of finding out which of the two textbox has been in focus last?
Thank you
The most fool proof way is to catch EVT_SET_FOCUS in your text controls and remember the last one that received it. This is not more difficult than what you are doing but should work without problems.
FWIW EVT_KILL_FOCUS can't, unfortunately, be consistently implemented on all platforms, in particular GTK+ doesn't give any information about the window focus is being lost to.
In think u mean event.GetWindow().GetId(). Though I'm not sure how ur casting from int to string.

MaskedTextBox positioning issue - WP7.1

I'm creating the MaskedTextBox in WP7.1 In that i want to select all text in the first click. in the second click,caret position should be the clicked position. But caret position always going at the starting or ending positions wherever i clicked inside the MaskedTextBox.
Please anyone help me to fix this issue.
protected override void OnGotFocus(RoutedEventArgs e)
{
if (IsFirstClickSelect)
this.SelectAll();
base.OnGotFocus(e);
}
For the first click, text is focused and selected all text inside got focus method. for the second click we could not catch he GotFocus method because it is already focussed. So Please tell me to set the clicked position.
Thank you.
This is the default behaviour of TextBox in Windows Phone 7.1

Changing ListBox selection is not moving changes from BindingSource to DataSet

The answer to this question may turn out to be, "Don't use typed DataSets without using the Binding Navigator."
I am curious, however, about the behavior I'm seeing.
So, I created a form where every control was dragged from the data sources explorer.
I deleted the Binding Navigator because it is ugly and inappropriate for this particular form.
I added a ListBox and set the DataSource to the BindingSource.
Notice that the ListBox is not bound, it is just filling itself from the BindingSource.
By some magic that I wasn't counting on, moving around in the ListBox is navigating the BindingSource and all other controls are updating accordingly.
I can make changes to the bound controls and explicitly call EndEdit on the BindingSource and then update the DataSource through the Table Adapter. Works great.
When I make changes in the bound controls and click a new option in the ListBox, I want to be able to check for changes and prompt to save or reset if there are any.
Here is the strange part that I haven't been able to figure out.
No matter what event I attach to, DataSet.HasChanges doesn't return true until the second ListBox change.
I've searched and tried dozens of suggestions, most of them ridiculous, but a few that seemed promising.
No luck.
Edit: It isn't the second click that is significant, it is when you click back on the original (edited) item.
Since asking the question, I've learned a bit more about BindingSources, DataSets and TableAdapters.
Here is what works:
private void MyListBox_Click(object sender, EventArgs e)
{
this.myBindingSource.EndEdit();
if (myDataSet.HasChanges())
{
if (MessageBox.Show("Save changes?", "Before moving on", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
myTableAdapter.Update(myDataSet.myDataTable);
}
else
{
myDataSet.RejectChanges();
}
}
}

Resources