DateTime Control ValueChanged Event, C# - winforms

I've got an SQL Query that runs when someone changes the Date on the DateTime Control on my Windows Form.
The Query is (currently) fired whenever the DateTime Control's ValueChanged property is fired.
This works poorly because:
If someone is trying to use the Control's scroll feature to go from January back to last September, the ValueChanged event fires once for each month (makes the GUI slow and makes unnecessary SQL calls).
If someone manually updates the date by typing the value into the text box, the ValueChanged property does not fire.
I can not use the Control's CloseUp property to solve #1 because then #2 would not fire.
A TextChanged property would be nice, but the DateTime Control does not expose one of those properties.
What is the best way to tell when my date has really been changed? (I'm not adding a timer that polls the form, either)
Development Environment: VS2008
Framework: 3.5
Language: C#
Target: Windows PC

(I'm not adding a timer that polls the form, either)
You exclude the one thing you should do to solve this problem. Then again, you wouldn't use a timer to poll the form, you start one in the DataChanged event handler. The Tick event handler disables the timer and runs the query. Make it a second or so. Add a button if you think that slows down the user too much.
A distant second choice could be an asynchronous query that you can cancel. Like SqlCommand.BeginExecuteXxxx(). Works well for the UI, not so well for the dbase server load.

Related

Does WPF use INotifyPropertyChanging

I wonder if WPF infrastructure utilizes INotifyPropertyChanging event on binding or its developers have plans to do it in future releases. Appreciate any link to respective information
Edit:
The idea behind my question was that I was recently being unable to cancel SelectionChanged event in DataGrid. Being bound to something like MySelectedProperty in my view-model it listens (I hope) to PropertyChanged("MySelectedProperty") to actually select different row. So I wonder why couldn't it listen to PropertyChanging("MySelectedProperty") to cancel the selection when I set Cancel to true

Lots of bindings, really slow, are binding active even if attached UIElement not visible?

I'm developing a WPF application that heavily relies on DataBinding.
Basically the app has several tabsheets each of which have ~50 elements using DataBinding to my ViewModel. Some of the binding are a bit complex with datatriggers and converters to display images based on binding results and so on.
Performance is good when I start the application, but as I navigate each of the tabsheets its getting slower and slower (and CPU usage increase). After I've navigate, lets say, 10 tabs, the application is almost unusuable, hanging for a couple of seconds everytime the binding sources fires de PropertyChanged events.
It seems as if binding targeted to visual elements that are not visible (because they are in a different tabsheet than the current one) are still processing, running the converter, and updating the visual control.
Is there any way to disable this? It would be an option to implement my own TabControl that disables every binding for non visible tabs, but havent found how to do this yet.
Any other suggestion would be appreciated!
As a side note, that may be important: every binding source raises its own PropertyChanged every ~5s that is the time we are reading the values from a device in the viewmodel. So, every 5s or so around 300 objects that implements INotifyPropertyChanged raise simultaneously the PropertyChanged event and at this instant is when the application freezes for a couple of seconds.
Due to the nature of the application, is not a option to slow down the update to anything more than 5s.
I am not MVVM but I thought in MVVM only the active tab was rendered.
In non MVVM what I do is for EVERY property I detect if it is the active tab and if not the active tab then I have it return nothing or a default value. TabControl has a SelectedIndex property.

PivotViewer FilterChanged event

I am working on a reporting app using PivotViewer. There are two controls on my grid. One is PivotViewer and the other one is a reporting Panel. After a user changes the filter of the PIvotViewer, I will generate the report on the report Panel in real time based on the remaining items in the current collection of the PivotViewer (InScopeItems). FilterChanged seems like the perfect event to hook up. However, it seems FilterChanged event is fired BEFORE the filter change.The InScopeItems don't change in the call back.
What I want is an event AFTER the filter change.
Right now the reports are very funny because it's showing the last report before I change the filter.
What's the recommended event? This seems like a very common user case but I couldn't find any solution. Thanks!
The best way to track changes to InScopeItems is to track the property itself. If you case is to a INotifyCollectionChanged object, you will have access to a CollectionChanged event. This should get you where you need to go.
Here is an example:
(pViewer.InScopeItems as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(MainPage_CollectionChanged);

Animation with MVVM pattern

What is the best way to trigger an animation while using the MVVM pattern? More specifically, I have a form which has several fields. When a user click's the save Button, I would like to show an animation. I have been able to achieve this by exposing a property ShowMessage and setting it to True and a DataTrigger picks up this value and starts an animation. However, while the animation is still active, I would like to reset the form to a clean state. So far I've done the reset by subscribing to the Complete event on the Storyboard and resetting the view model's state on that event.
Ideally I would like to be able to somehow trigger an animation from the view model (because the save would be an asynchronous operation) and let the animation run to completion. The way I have it now wouldn't work because once I change the value of the ShowMessage property (on the reset), the animation stops and doesn't run to completion.
Does any one have a better solution?
Thanks!
Two options comes into my mind. The first is VSM, and the second is attached behaviors. You may find useful the following post from Marlon Grech: Animations and MVVM.
Hope this helps.

Silverlight DatePicket and TimePicker initialization

I'm using DatePicker and TimePicker from the toolkit. I've got to hook up on the SelectedDateChanged event and I'm also setting the values in code.
My issue is that when I initialise both controls the SelectedDateChanged event doesn't get fired synchronously. That's quite a big issue for me because it means I initialise the control and some time later the event gets fired and changes the current value (because that's what I do in the event handler).
Is there any work around? I tried to listen to some event that get fired once everything is initialized but there's nothing apart from the Loaded event of each control (which is really ugly and gets fired each time the tab on which the controls are gets activated).
EDIT: my problem seemed to go away for a while so I didn't bother looking into it in case it came back. Now it did :(
I use MVVM and initialize the controls within the view in the constructor. Then, when the VM gets the view, it sets the default value as well.
Unfortunately, by the time the VM sets the value the controls haven't got initialized and happen to get themselves intialized some time later (even though I set them in the constructor). They then override the default values.
There's definitely an issue. However I found a very easy workaround: if I bind the control and don't listen to the SelectedDate event I get the change synchronously and everything works fine.
Took me ages to figure that out but now it's working.

Resources