Saturday, November 3, 2012

Changing Visual State in Custom Control

Call VisualStateManager.GoToState(control, strStateName, useTransitions)
strStateName is mapped to a TemplateVisualStateAttribute of the control class.

Thursday, October 18, 2012

PrintDocument

sample: http://web.archive.org/web/20101128170826/http://silverlightips.net/2010/03/27/multi-page-printing-in-silverlight/
including:
PrintDocument .PrintPage (event) .Print (method)
PrintPageEventArgs .PageVisual (UIElement) .PrintableArea (Size) .HasMorePages

Also usage of Canvas.TopProperty in SetValue

Monday, October 15, 2012

Dependency Properties vs. Attached Properties

Attached Properties use an accessor style that XAML parser can use, i.e. SetPropertyName
As opposed to regular dependency properties that use regular Set/Get accessors.

For attached properties see: http://msdn.microsoft.com/en-us/library/cc265152(v=vs.95).aspx

For regular dependency property requirements see Checklist for Defining a Dependency Property
Nice sample of custom dependency object here (bottom)

Silverlight 4 Validation

This two-part series sums it up:
http://www.silverlightshow.net/items/The-validation-story-in-Silverlight-Part-1.aspx
http://www.silverlightshow.net/items/The-validation-story-in-Silverlight-Part-2.aspx

SL 3 supports ValidatesOnExceptions=True, NotifyOnValidationError=True
Throw exceptions in setters. Optionally use validation attributes on model properties: this requires Validator.ValidateProperty(value, new ValidationContext... in setter
Can use CustomValidation attribute and sdk:ValidationSummary tag

SL4 introduces IDataErrorInfo plus ValidatesOnDataErrors=True tag
and INotifyDataErrorInfo plus ValidatesOnNotifyDataErrors=True

Can customize the validation states in Blend: Default transition, Valid, InvalidUnfocused, InvalidFocused

Sunday, October 14, 2012

Easing Functions - XAML Syntax

DoubleAnimation...DoubleAnimation.EasingFunction vs. DoubleAnimationUsingKeyFrames...EasingDoubleKeyFrame

Samples here
In the previous example, the easing functions are applied to a From/To/By animation. You can also apply these easing functions to Key-Frame animations using either EasingDoubleKeyFrame, EasingPointKeyFrame, or EasingColorKeyFrame 

Friday, October 5, 2012

DependencyObject/DependencyProperty

DependencyProperty's (e.g. a Canvas' left, right) are assigned to DependencyObjects, e.g. UI elements. http://blog.hackedbrain.com/2004/12/04/understanding-dependencyobject-and-dependencyproperty/

Example usage of DependencyProperty to add second ContentPresenter to a ControlTemplate

For the uncommon cases where a settable property on a DependencyObject is not a dependency property, that property will be unable to support animation, data binding, or FrameworkElement styling.
http://msdn.microsoft.com/en-us/library/cc221408(v=vs.95).aspx

Tuesday, October 2, 2012

XAML Concepts


See http://msdn.microsoft.com/en-us/library/ms752059.aspx for descriptions of:

XAML Object Elements (represent WPF types)
Property Element Syntax (vs Attribute Syntax)
Markup Extensions - for setting property dynamically at runtime
Type Converters (e.g. Margin/Thickness)