I begin to apply the Mvvm design pattern in my current project and the framework I used is Mvvm Light toolkit. Now I encoutered a problem when using the EventToCommand to handle "GotFocus" event.
The xaml file is something like:
<TextBox x:Name="TextBox1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="GotFocus">
<cmd:EventToCommand Command="{Binding TestCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
I want to execute the TestCommand in the view model whenever the "GotFocus" is fired.
But the problem is that the "TestCommand" is not executed for the initial "GotFocus"(ie. when the window is loaded). I have debugged and found that the "GotFocus" event was actually fired but the Trigger was not invoked for unknown reason.
Then I set the focus in the "Window.Loaded" event handler, it still failed.
protected void WindowLoaded(object sender, RoutedEventArgs e)
{
FocusManager.SetFocusedElement(this, TextBox1); // The focus is moved to TextBox1 but the associated command is not executed.
}
But If I set the focus in the "Window.Activated" event handler, it is OK.
protected void WindowActivated(object sender, EventArgs e)
{
FocusManager.SetFocusedElement(this, TextBox1); // The focus is moved to TextBox1 and the command is executed.
}
I am very confused about what happened. Could anyone explain it in detail?
Related
Context: In a Vaadin 23 application there is a form that is reachable directly via URL. It registers a BeforeLeaveListener with UI.getCurrent().addBeforeLeaveListener(bll);. The implementation of the BeforeLeaveListener is this:
#Override
public void beforeLeave(BeforeLeaveEvent event) {
ContinueNavigationAction action = event.postpone();
askAndProceedIfOk(() -> {action.proceed();});
}
It explicitly postpones the BeforeLeaveEvent and explicitly proceeds the event.
In the application there's a second form that is opened in a modal dialog with the option to close it.
Dialog modalDialog = new Dialog();
modalDialog.setCloseOnEsc(true);
modalDialog.setCloseOnOutsideClick(true);
modalDialog.setModal(true);
The BeforeLeaveListener doesn't work here, but a ComponentEventListener<Dialog.DialogCloseActionEvent> does:
modalDialog.addDialogCloseActionListener(new ComponentEventListener<Dialog.DialogCloseActionEvent>() {
#Override
public void onComponentEvent(Dialog.DialogCloseActionEvent event) {
myForm.askAndProceedIfOk(() -> {modalDialog.close();});
}
});
Surprise: I am surprised that BeforeLeaveEvent and DialogCloseActionEvent work different:
BeforeLeaveEvent offers postpone() and proceed()
DialogCloseActionEvent seems to be implicitly postponed just by showing another modal Dialog that asks the user whether to save unsaved changes. And I do have to close the modal dialog explicitly.
Question: Is it right that both events (with a similar task) work that different or do I miss some details here?
I have a JavaFX WebView that is being updated with background messages and executes scripts to update the page.
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
try {
webEngine.executeScript("foo1();");
} catch (Exception e) {
// JSException: TypeError: 'undefined' is not a function
}
}
}
});
This normally runs correctly, however when I create a second WebView with it's own WebEngine and try and execute foo2() on that second page, at about the same time as execution foo1 on the first page, I get this:
JSException: TypeError: 'undefined' is not a function
I could have a synchronization block, but it seems it should be unnecessary since the webEngines are suppose to be independent, are there other solutions?
This is a session management error in your program.
2 WebViews compete for the same session, and ... assuming you haven't implemented protocol and session handlers, including cookie storage, etc..., the second webengine which is unable to obtain the connection will run the script over something that doesn't exist ( as far as the webengine is concerned ) hence an UNDEFINED object.. thus the error.
I'm using this stuff over HTTPS protocols, and have experienced this.
I'm very new to Dart, and I'm encountering a problem with this code:
DivElement badge = querySelector('.badge');
badge.onClick.listen(onBadgeClick);
The event handler looks like this:
void onBadgeClick(MouseEvent e){
print(e.relatedTarget);
}
I get this exception
Exception: Unsupported operation: Cannot call matchingTarget if this
Event did not arise as a result of event delegation.
How can I get the element that the click is associated with?
e.target should you give the element that created the event. If you set a breakpoint in DartEditor the code execution halts on the line with the breakpoint and you can investigate the properties of the e instance.
In Polymer there is a this.job() function that handles the delayed processing of events. How do you access this functionality from polymer.dart?
#override
void attached() {
super.attached();
dom.window.onMouseMove.listen(mouseMoveHandler);
}
PolymerJob mouseMoveJob;
void mouseMoveHandler(dom.MouseEvent e) {
print('mousemove');
mouseMoveJob = scheduleJob(mouseMoveJob, onDone, new Duration(milliseconds: 500));
}
void onDone() {
print('done');
}
If the job isn't rescheduled for 500ms it is executed.
In polymer this is often used during initialization when
xxxChanged(old);
is called several times succinctly because xxx is updated on changes from several other states which are initialized one after the other but it is enough when xxxChanged is executed for the last update (a much shorter timeout should be used then like 0-20 ms depending whether xxxChanged is only called from sync or also from async code.
Another situation where I used this pattern (but not using PolymerJob) is where an #observable field is bound to a slider <input type="range" value='{{slider}}'>.
This invokes sliderChanged(oldVal, newVal) very often in a short interval when you move the knob. The execution of the update is expensive and can't be finished between two such calls see http://bwu-dart.github.io/bwu_datagrid/example/e04_model.html for an example.
Without some delayed execution this would be very cumbersome to use.
Try using Future:
doJob() => print('hi');
new Future(doJob).then((_) => print('job is done'));
Here are the docs for the Future class.
I need to run one of my macro when a page is published. I there any way to do this in umbraco
There are some events you can hook into. In your case you might use the Document_AfterPublish() event.
static void Document_AfterPublish(Document sender,
umbraco.cms.businesslogic.PublishEventArgs e)
{
// your code
}
// hook into the event
Document.AfterPublish +=
new Document.PublishEventHandler(Document_AfterPublish);
Also look at this and this links which could be helpful.