Is there not an event that occurs only when there has been some sort of visual change to an object. So for example if it were a video or animated object it would be firing as often as EnterFrame. However, if it were some sort of input control just sitting there doing nothing visually, then the event wouldn't fire until the visual state changed as a result of some sort of user input for example.
I've tried dozen's of events and none of them seem to fire this way.
For visual components about the closest you're going to get is FlexEvent.UPDATE_COMPLETE which will fire after an object has it's commitProperties(), measure() and updateDisplayList() called. If you're subclassing the component, then overriding updateDisplayList() and handling (or throwing you're own event) in there would ensure that you're only getting the event when something visual changes.
For video, you'll want to listen to VideoEvent.PLAYHEAD_UPDATE
Related
I have a TabView inside of my ContentPage and to keep things clean I usually put my tabs in a ContentView
My ContentView in this example has a few Entry controls. I want to subscribe to the TextChanged event for the control so I can display a character counter label on the page.
Now I'm not sure if this is correct or not but I keep these UI functions in the code behind as to my knowledge they have no place in the VM.
The issue is; in the ContentPage there is no way to get a reference to the control when its buried in a ContentView and if I try to move the logic to the ContentView there is no access to the usual OnAppearing & OnDisappearing methods. I'm using MVVMCross and at the moment I'm subscribing to the event in the OnBindingContextChanged method. However, I cant see anything that gets triggered when the page is closed / popped.
I was over thinking this as usual.
What I was wanting to achieve was to simply update a Label when the text in an Entry changed. I keep my UI specific code in the XAML and code behind but I was having issues in un/subscribing to the TextChanged events in the code behind.
I don't know why I don't think of this before; just wire the TextChanged event in the XAML instead of doing it in the code behind and that way the unsubscribe is already taken care of.
As a followup to this question (https://stackoverflow.com/questions/28567211/how-to-log-control-hierarchy-in-net), is there any global way to capture all click events in either Silverlight or ASP.NET?
I am basically asking if there is some way to attach a global click event handler so that I can run some code on every click event captured against all controls that handle click events, wihtout having to add the event handlers manually to each control.
If you can, I'm wondering how this can be accomplished without having to explicitly add an event handler to every control manually. One thought I had was from a top ASP.NET page or Silverlight app to traverse the entire Control tree looking for ButtonBase controls (or the equivalent in ASP.NET) and add a new event handler for the click event. However, I don't love the idea of traversing the entire tree and doing it this way. I guess in Silverlight it wouldn't be so bad as it would only have to be done when the app is loaded, but with ASP.NET I would imagine it would happen on every PostBack?
It looks something like System.Windows.EventManager.RegisterClassHandler() would do it, but I don't believe I have access to that in Silverlight, or any equivalent in ASP.NET.
In Silverlight you can attach a mouseClick event handler to the UI tree RootElement. You do not need to traverse the tree, the mouseclick event bubble up the whole tree - even if they are handled by intermediate nodes. If you want to catch also events that are already handled, you have to specify this when attaching the handler (see the bool param in my code below).
...
var root = System.Windows.Application.Current.RootVisual;
MouseButtonEventHandler handler = HandleRootMouseLeftButtonDown;
root.AddHandler(UIElement.MouseLeftButtonDownEvent, handler, true);
...
private void HandleRootMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// do some magic...
}
I tried with a minimal application, just a textbox and a button. The button is binded to a RelayCommand instance, and the CanExecute method just return true or false with a random. The textbox text is binded with a string property.
What's making me mad is that the CanExecute method is "always" called: a change of the element focused, a key pressed in the textbox, it seems that everything fires a call to my CanExecute method.
Is this a "feature" of the mvvm light toolkit? Does this happen in a "normal" wpf application?
Yes, I know, I think I should know more about the commandind system in wpf... ;-)
Thanks for answers!
David
CanExecute is used to determine if the current state allows the command to execute. This is usually tied to the IsEnabled property to disable the command.
This should also be tied to a property on your ViewModel that indicates if the current view state allows executing.
It is tied to any event trigger on the hosting window, since any event could cause a change to the CanExecute state.
This link confirms it is fired on any event in the hosting window.
http://robburke.net/2008/04/23/wpf-command-pattern-when-does-it-query-canexecute/
Why do you think it being called all the time is an issue? As long as you don't have any intense logic in the bound property it should be fine.
I have two separate advancedDataGrid instances (let's call them A and B). What I'd like to do: when clicking on grid A I'd like
for grid A to handle the click normally (i.e. default advancedDataGrid behavior)
for grid B to receive a click event a certain location and handle such event using advancedDataGrid default behavior (i.e. without having to write a handler for such click).
Is this possible?
I've managed to dispatchEvent a MouseEvent.CLICK to grid B and to handle such event by creating an event listener, but really I'd like for grid B to handle the event on its own (i.e. without having to re-rewrite a handler), and that doesn't seem to be the case. Is MouseEvent.CLICK even the right event?
any help, pointers, advice would be immensely appreciated.
thank you!
There is no way to execute code after an event is dispatched without using an event listener.
I'm unclear exactly what you're trying to do, but there is no reason why you can't dispatch an event on an object that is not it's own. Instead of doing:
myContainerWithAAndB.dispatchEvent(MouseEvent.CLICK);
You can do this:
gridB.dispatchEvent(MouseEvent.CLICK);
And if there is a default handler in the gridB class to handle such an event, that handler should fire; just as if gridB's own code had dispatched the event.
The short version is that I have nested FormViews. I would like the child FormView to only change modes when the parent does so as well, so I handle the ParentFV.ModeChanging event and call ChildFV.ChangeMode within that...
For some reason, the Child FormView's mode doesn't change... nore does the Child's ModeChanging event appear to get fired...
Why would this not work?
EDIT: I came up with a workaround, hooking the Inserted and Updated events and using the KeepIn*Mode to prevent them from going back too early... setting the mode itself on page_load according to the current DynamicData mode...