Monotouch: how to verify UITextFields - uitextfield

I have several UITextFields that I want to do a numeric check on when the user taps the Next key on the keyboard. I know I can do it when the k/b becomes first responder... I want to check the field before the user goes on to the next field.
How do I do this?

void HandleTxtHIhandleEditingDidEnd (object sender, EventArgs e) {
if(!decimal.TryParse(txtHI.Text, out x)) {

Related

How to notify user caps lock is turned on within a password field in C#?

I'm not a pro, but What i want in my Login panel (a windows form) which hass a pasword Text field,
I want to apply the same idea here, 'window Xp password text field had', in which if Caps lock is on, a small String gets to Popup saying CAPSLOCK is On, `
private void txtPass_TextChanged(object sender, EventArgs e)
{
txtPass.PasswordChar= '*' ;
}
`
this is my Password button.
The magic happens in this line
Application.EnableVisualStyles();
If this line is missing then you loose that functionality together with the flat appearance of many controls and so on.
The line should go before any attempt to create user interface objects and usually is present in the Main static method that starts your application
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new yourStartupForm());
}

Devexpress GridControl : Prevent new row added automatically

Please guide me how to prevent new rows added automatically on DevExpress.XtraGrid.GridControl
I want to control when new rows is added, in my case i'm using a keydown event (CTRL + I ) for this task. But the grid keep adding new rows automatically if i move the focus (cursor pointer) to the area right below to the last row and click.
The GridControl.MainView is a BandedGridView, which contains the datasource.
You can use BandedGridView.OptionsView.NewItemRowPosition property. You can set its value to NewItemRowPosition.None to hide new item row.
Another way is to handle BandedGridView.ShownEditor event. Inside of this you can check if BandedGridView.FocusedRowHandle property is equals to GridControl.NewItemRowHandle and cancel editor activation.
Here is example:
private void bandedGridView1_ShowingEditor(object sender, CancelEventArgs e)
{
if (bandedGridView1.FocusedRowHandle == GridControl.NewItemRowHandle)
{
// Do here additional checks if you need. After your checks set e.Cancel to true.
e.Cancel = true;
}
}
You can handle the ValidateRow event. If you set e.Valid = false you wont add a new row. So check if your object is empty or invalid and just if the needed values are typed you give the row free.
private void grvMyView_ValidateRow(object sender, ValidateRowEventArgs e)
{
if (grvMyView.IsNewItemRow(e.RowHandle))
{
MyObject obj = grvMyView.GetRow(e.RowHandle) as MyObject;
e.Valid = obj.IsValid();
}
}
As of version 15 you can simply set your TableView's NewItemRowPosition to NewItemRowPosition.None. Be sure to call CommitEditing() on your TableView first.

Manipulation_started doesn't work on a map

Hi to all I'm trying to set a listener for the ManipulationStarted, ManipulationDelta, ManipulationCompleted of a map to detect if the user drag a map around, but looks like none of those events are launched if I drag the map. If I set a tap listener for the map ManipulationStarted is correctly launched.
What I'm doing wrong?
xaml code:
<Controls:Map x:Name="myMap"
Grid.Row="0"
Loaded="myMap_Loaded"
ManipulationDelta="myMap_ManipulationDelta"
ManipulationCompleted="myMap_ManipulationCompleted"
ManipulationStarted="myMap_ManipulationStarted"
Tap="myMap_Tap">
code behind:
private void myMap_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationdelta");
}
private void myMap_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationcompleted");
}
private void myMap_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationstarted");
}
private void myMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Debug.WriteLine("Event:: MyMap_tap");
}
I'm on a normal page, no pivot or panorama.
I'm afraid that you won't be able to handle those events because Map control intercepts them. Although there is a property UseOptimizedManipulationRouting, but as I've tested it - it doesn't help much in this situation.
I dont't know what you are trying to achieve, but if you don't need ManipulationDeltaEventArgs then maybe you consider using different events such as: MouseEnter, ResolveCompleted and CenterChanged.
If you need them then as JustinAngel suggested here you can follow these instructions and use Touch.FrameReported event for your purpose.
EDIT - code sample
If I've understood you properly, you would like to know when the User touches the Map, MouseEnter won't be the best choice as it will work only first time, then if mouse didn't leave the Map (user touched somewhere else), it won't fire again. Better solution here (following instructions above) can be such a code:
public MainPage()
{
InitializeComponent();
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint point = e.GetPrimaryTouchPoint(myMap);
if (point.Action == TouchAction.Move && point.Position.Y > 0)
{
MessageBox.Show("User is Moving Finger over the Map!");
}
}

Clearing all selected items in _SelectionChanged()

I have a multi-select ListBox and I try to deselect all items like this:
private void _SelectionChanged(object sender, SelectionChangedEventArgs e) {
foreach(var i in e.AddedItems) {
// do whatever - works ok
}
//then clear all selected - doesn't work
((ListBox)(e.OriginalSource)).SelectedItems.Clear();
}
I have tried (e.OriginalSource as Listbox).SelectedItems.Clear() as well, but it just throws an error.
Any advice would be appreciated, thanks.
EDIT:
After many tries this works:
((ListBox)sender).SelectedItem = null;
regardless of the fact that it is multi- not single- select ListBox!
The following is what you were actually looking for:
((ListBox)sender).SelectedItems.Clear();
The reason calling .SelectedItem = null works is just the behavior of the ListBox. Both end up doing the same thing. The more "correct" one is the line I gave you.

Lock app with password

In WP application we need to provide user option to lock app with password.
As I understand WP app lifecycle, I need to put navigation to LockPage in App.Application_Activated, App.Application_Deactivated and start page, but I can not use NavigationService in App class...
I do not want to put navigation code to lock page in each other pages, or there is no other options?
I writed own solution, but may be it is not so elegant as it could be.
App locking logic: User enable app locking with password, we handling Application_Deactivated and Application_Closing events in App class and marking app as locked if user enabled this option. Then, on each page we should put check: is app currently locked and if it is, we should navigate to AppLockedWithPasswordPage. On AppLockedWithPasswordPage we need to check user`s password, if it is correct call NavigationService.GoBack().
So we need to do 6 steps:
You should choose where to save IsAppCurrentlyLocked (bool flag), AppLockPassword (string) and IsUserEnabledAppLockWithPassword (bool flag). I had chosen IsolatedStorageSettings
Create AppLockedWithPassword page, where you need to show TextBox and Button, do not forget to provide option for user to reset AppLock of course with deleting app data
AppLockedWithPasswordPage should prevent BackButton navigation, so preventing it:
// AppLockedWithPasswordPage
protected override void OnBackKeyPress(CancelEventArgs e)
{
// Preventing back key navigation
e.Cancel = true;
}
Check password on button click
// AppLockedWithPasswordPage
private void UnlockAppButton_Click(object sender, RoutedEventArgs e)
{
if (PasswordBox.Password.Equals(IsolatedStorageSettings["AppLockPassword"]))
{
NavigationService.GoBack();
}
else
{
// Say user, that password incorrect, etc...
}
}
In App class find Application_Deactivated (to handle app minimizing (windows button)) and Application_Closing (to handle when user closing app) methods, we should mark app as locked if user enabled this option when this events happens
private void SetIsAppCurrentlyLockedFlagIfUserEnabledAppLocking()
{
if ((bool)IsolatedStorageSettings["IsUserEnabledAppLockWithPassword"])
{
IsolatedStorageSettings["IsAppCurrentlyLocked"] = true;
}
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
SetIsAppCurrentlyLockedFlagIfUserEnabledAppLocking();
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
SetIsAppCurrentlyLockedFlagIfUserEnabledAppLocking();
}
And final step, on all pages you want to lock you should add check in OnNavigatedTo method which will navigate to AppLockedWithPasswordPage if app is currently locked
// Create some class, like PagesUtils or so on with check method
private static Uri uriToAppLockedWithPasswordPage = new Uri("pathToAppLockedWithPasswordPage", UriKind.Relative);
public static void NavigateToAppLockedWithPasswordPageIfAppLocked(PhoneApplicationPage page)
{
if ((bool)IsolatedStorageSettings["IsAppCurrentlyLocked"])
{
page.NavigationService.Navigate(uriToAppLockedWithPasswordPage);
}
}
// In each page you want to lock add
protected override void OnNavigatedTo(NavigationEventArgs e)
{
PagesUtils.NavigateToAppLockedWithPasswordPageIfAppLocked();
base.OnNavigatedTo();
}
P.S. of course real code is much better, this is just simple example, I hope it will help you
You should add the check in the Application_Launching and Application_Activated events.
The launching event for when the app is first opened and the activated one for when the user returns to the app after having left to do something else.
Have these events both set a flag and have the base page that all your pages inherit from check for this flag when navigated to. The check should be for if the flag is set, if it is, show the login prompt and then clear the flag after successful password entry.
This approach will handle FAS, FAR & deep linking, in addition to starting the app normally.
Beware Some choosers will trigger the activated event when they return to the app. Add extra handling for these as appropriate / if necessary.
Why not create a start page where the passwords is entered?
For instances you have your MainPage.xaml, create a InsertPasswordPage.xaml reference it on WMAppManifest as the start page:
<DefaultTask Name="_default" NavigationPage="InsertPasswordPage.xaml" />
And insert all the password logic on the InsertPasswordPage.xaml, when the user successfully logins just navigate to your main page ;)
EDIT: As Gambit said if the user pressed the back button he will return to the insert password page, but you can solve this by removing from the backstack the page after the user logged in.

Resources