Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am working on a user control named DateMonthControl. It is supposed to show months between a min-date and a max-date - and to enable the user to select a specific month.

That is: Minimum month may be september 2011 and maximum month may be april 2014. The user must then be able to select a month between these two - for instance may 2013.

The xaml for the control looks like this:
SQL
<local:DateMonthControl
            MinDateMonth="{Binding Source={StaticResource myDataSource}, Path=MinDateMonth}"
               MaxDateMonth="{Binding Source={StaticResource myDataSource}, Path=MaxDateMonth}"
               SelectedDateMonth="{Binding Source={StaticResource myDataSource}, Path=SelectedDateMonth}" />


My problem is, that I really do not want to calculate anything in my control before MinDateMonth, MaxDateMonth - and possibly SelectedDateMonth has been set by the framework.

(I need to disable the months not allowed in the years allowed. In this example I need to disable january-august 2011 and may-december 2013 - and I don't want to do that on the default values which is DateTime.Min, DateTime.Max and DateTime.Now).

So.. is there some event my user control may hook into, which get called just after all dependency properties has been initiated? - but possibly before the control has been rendered and databinding occurred?).

Thx
Posted

Hi,

In WPF, we have a system called property value coercion, which is entirly dedicated for the above requested scenario.

Please take a look at the following link to know about CoreceValueCallback.
http://msdn.microsoft.com/en-us/library/system.windows.dependencyobject.coercevalue.aspx[^]

That link defines what is Property Coercion. Just google about CoerceValueCallback. You would get pretty great links.

Hope that solves your question.
 
Share this answer
 
This is perhaps the right direction.. however.. I need to do something (setup a observablecollection) based on MinDateMonth, MaxDateMonth and SelectedDateMonth.

I want to call a method, when all three has been updated (either from input or from default values - since SelectedDateMonth is optional - it should set to MinDateMonth when not supplied).

I've allready got it implemented so that the method is called. This is done by calling it in all three ValueChanged CallBack methods. Since SelectedDateMonth always gets set last (because of CoerceValue callbacks) the collection ends up with the right data.

However.. it may be called three times depending on the order of the SelectedDateMonth, MinDateMonth and MaxDateMonth in the control that uses this user control.

I don't want that - it's potential very wastefull (since min and max default is datetime.min and datetime.max) ... and preventing my collection-building logic from being called more than once.. well.. that code I wrote looks very ugly.

So my question is: How do I call a specific method, when all input-data has been collection (Min/Max/Selected or Min/Max) - and only then.

I want the SelectedDateMonth to reset to Min/Max if either of those gets changed, leaving SelectedDateMonth outside the new Min/Max scope. This seems to be the standard example - and I've pretty much copied it (but right now, I seem to have misplaced the link to the microsoft page).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900