Accessing on-screen elements from delegate function in WP7 - windows-phone-7

Suppose that I have a registration screen, and when the user clicks the "Register" button an asynchronous operation takes place, at the end of which a delegate method is invoked. I want the button to be turned off when the user clicks it (that part is easy), and for the button to be re-enabled if the registration fails (server declined the registration). How do I access this button's properties from the delegate function?

Assuming you've declared the Button's name in XAML, in the delegate callback function, I'd do something like (The Dispatcher.BeginInvoke is necessary to execute the code on the UI thread):
Dispatcher.BeginInvoke(() =>
{
MyRegisterButton.IsEnabled = true;
});

Related

Is there a way to trigger an action without a button click

I'm about to develop an add-in that will automatically pull some data from emails and modify some fields in our database. However this extraction could be a bit error prone so we wanted a layer of human verification when it occurred.
We do this in gmail already, when the user open an email and we find something we want to extract we display a confirmation pop-up, and this feature is very well received by our clients.
I am planning on using the dialogbox but it seems to trigger this the action to display the box needs to be attached to a ui element for the user to click.
Is there any way to tigger an action pragmatically, without a users click?
Take a look at the pinnable task pane available for Outlook add-ins, see Implement a pinnable task pane in Outlook for more information. There you can implement the ItemChanged event handler. The event handler should accept a single parameter, which is an object literal. The type property of this object will be set to Office.EventType.ItemChanged. When the event is called, the Office.context.mailbox.item object is already updated to reflect the currently selected item.
Office.initialize = function (reason) {
$(document).ready(function () {
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, itemChanged);
UpdateTaskPaneUI(Office.context.mailbox.item);
});
};
// Example implementation
function UpdateTaskPaneUI(item)
{
// Assuming that item is always a read item (instead of a compose item).
if (item != null) console.log(item.subject);
}

VB6 _Validation event not firing when tabbing to Cancel button with CausesValidation = False

I have a situation similar to the following simplified description:
A form with a TextBox (call it txtQty) in which a user can enter an integer. The event txtQty_Validate is used to validate the user input and force them to correct any errors before changing focus. This works great with all other controls on the form except for said txtQty. I assume that this is because the Cancel button on the form has the property CausesValidation necessarily set to false; thus when the user Tabs from txtQty to the Cancel button (whose TabIndex is next) it does not appropriately trigger the txtQty_Validation event.
My first instinct was to simply go to the txtQty_KeyPress event (which I am already using to make the RETURN key behave as TAB key) and capture the TAB key and temporarily toggle the CausesValidation property to allow the txtQty_Validation event to fire. However, it seems as though capturing the TAB key is not as easy as I had thought it would be.
Any suggestions? I assume that this cannot be the first time anybody creating a Form has come across such a situation.
Thanks
You could try this in the Cancel GotFocus event.
Dim b As Boolean
Call txtQty_Validate(b)
If b Then txtQty.SetFocus
Assuming you have something like this
Private Sub txtQty_Validate(Cancel As Boolean)
If Not IsNumeric(txtQty.Text) Then
Cancel = True
End If
End Sub

JavaFX: default button won't fire events

In my code I have bound the defaultProperty of a button to some other properties like so:
BooleanBinding isAddResourceButtonDefault
= resourceNameTextField.focusedProperty().or(
resourceTypeComboBox.focusedProperty()).or(
divisibleResourceCheckbox.focusedProperty().or(
maxInstancesTextField.focusedProperty()).or(
addResourceButton.focusedProperty()));
addResourceButton.defaultButtonProperty().bind(isAddResourceButtonDefault);
The problem is that the addResourceButton won't fire absolutely any events on pushing Enter - neither OnAction, nor OnKeyPressed.
The default property gets set just fine - I double checked (using output and ScenicView). ScenicView also doesn't show any events being fired upon hitting keys. Any ideas?
I believe TextFields (and other TextInputControls) process and consume key events that occur on them. So pressing Enter on a text field will not fire an action event on the default button (because the key event never reaches the Scene).
If you are just trying to fire the button's action event handler when enter is pressed in one of the text fields, just add the same event handler to the text fields. E.g.
EventHandler<ActionEvent> addResourceHandler = event -> {
System.out.println("Add resource");
// ...
};
addResourceButton.setOnAction(addResourceHandler);
resourceNameTextField.setOnAction(addResourceHandler);
maxInstancesTextField.setOnAction(addResourceHandler);

jqGrid saveCell method returns nothing except gridelement. can i get true/false or can i pass a callback to saveCell?

I am using jqgrid 3.8. I have a grid which is having some editable columns.I also have an update button to save the grid contents on the server.
If user clicks on editable cell and changes the content and then clicks on update button, i am doing the following things.(after clicking on cell user directly clicks on update button)
first i am calling jqGrid 'savecell' method with iRow, iCol.
here the cell is being saved/ showing popup for validations.
but i want a callback to know whether cell is saved/not so that i can stop or continue my save functionality.
my sample code is like this
function updateGrid(){
// i have iRow, iCol references in beforeEditCell event as grideditRow, grideditCol.. these values r not getting modified nowhere else..
$(gridid).jqGrid('saveCell', grideditRow, grideditCol);
//logic to get grid data using getchangedcells and send ajax call to server.
var changedCells = $(gridid).jqGrid('getChangedCells', 'dirty');
}
how can i stop update logic after saveCell call if savecell is failed. saveCell is returning only jqgrid element.
is there any mechanism to get true/false from savecell or can i pass some callback to savecell?
There are afterSaveCell and errorCell events. One of the events will be called after saving the cell on the server. If you implement the corresponding event handler, you will be notified whether the saving of the new cell value was successful or not.

ApplicationBar is destroyed when canceling back navigation

I have a page with "internal navigation". That means that I show some list on that page and when user picks an item, I (download some data and) repopulate that list.
I made my own history stack, so when user wants to go back, I repopulate the list from history stack. User can go back by flicking or by clicking on hw back button.
Flicking works ok, but back button is weird.
I am canceling the back button event and instead I run my back navigation history. So I am still on the same page. BUT the back button click hides the application bar (even though I am canceling that event). And when I click it again and debug it, the ApplicationBar property is null.
// this overriden method causes ApplicationBar being hidden (or destroyed)
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Messenger.Default.Send(...some notification here...); // this runs the internal navigation
ApplicationBar.IsVisible = true; // this doesn't help and on the second try, it throws NullReferenceException
}
// this method is ok, repopulating is working without any problem
private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
Messenger.Default.Send( ...some notification here... ); // this run exactly same internal navigation
}
So question is - how to have ApplicationBar not destroyed/hidden? What is back button doing, when I cancel the navigation (it must do something with the AppBar)?
OK, this happens only when I use BindableApplicationBar and its Extensions (from here maxpaulousky.com).
It happens because Extensions handles back button event on page itself.
Solution was to check the Cancel property, and destroy it only when it's false (in BindableApplicationBar class in the Extensions).

Resources