Advertuse

Search This Blog

Your Ad Here

Wednesday 16 May, 2012

Value Coercion in WPF




What is value coercion?
If you are not familiar with value coercion, it is simply a mechanism by which related (or “interdependent”) dependency properties can be kept in sync and valid.
The quintessential example can be found within the Slider control. A Slider has both Minimum and Maximum properties. Clearly, it would be a problem if the Maximum value were allowed to fall below the Minimum value. Value coercion is used to prevent this invalid state from occuring.
In WPF, the Slider control (or more specifically, the RangeBase control) ensures that these property values stay valid by using a feature of the dependency property metadata called a CoerceValueCallback. Whenever the Maximum property value changes, it is passed through this coercion function. If the Maximum value happens to be less than the Minimum value, the function will coerce it to be equal to the Minimum value so that it is valid.


The coercion routine for the Maximum property looks something like this:
private static object CoerceMaximum(DependencyObject d,
    object value)
{
    double min = ((RangeBase)d).Minimum;
    double max = (double)value;
    if (max < min) return min;
    return value;
}
Whenever the related Minimum property changes, the control explicitly coerces the Maximum property. This ensures that the Maximum value stays valid with respect to the new Minimum value.
The property changed callback for the Minimum property looks similar to this:

WPF Architecture

Today I would  like to discuss some  core part of WPF architecutre. in  WPF ,Presentation Framework, Core Presentation and Media Integration Layer (milcore) Are The Three Major components of WPF architecture. These Are the Major portions of the WPF code. Milcore is cash en Unmanaged Code in order to enable tight integration with DirectX. DirectX engine is responsible for all display in WPF, allowing for efficient hardware and software rendering. CLR Provides fine control over the memory and execution. The composition engine in milcore is Extremely sensitive performance, and required giving up Many advantages of the CLR to gain performance
for more details  click on below link




WPF Architecture


INotifyPropertyChanged For ViewModel or For Model ?

INotifyPropertyChanged For ViewModel or For Model ?

compile by
Divyang Panchasara
Sr. Programmer Analyst
Hitech OutSourcing