WPF Tutorial
WPF Tutorial
WPF Tutorial
WPF Styles
- Only be applied to DPs
- Inline/ through ref to Style Property
- Self Key type:- If you dont specity key, it you can control x:Type to apply t
o all instances of that type,
- Can be used to Skin the applications, by defining, multiple skins each set of
styles defined for each type
- Styles can be extended by using BasedOn attribute pointing to another style,
This wires up both the styler
- Application gets to apply JUST one style to an element, Scoped from Narrower
to Wider
- Styles cascade down to the children of the applied element
- Styles can have properties which do not match target type, non matchin proper
ties are ignored
- Styles can have triggers, which only apply to the target of the element
- When binding data one can't provide your own containers in which case, ItemCo
ntainerStyle should be applied.
- Controls default look comes from styles coming from theme
- Controls default style coming from default theme, this is called DefaultTheme
Style
- Another Style comes from Application, called Application style,
- These 2 combine to create the look for the control, However Control can have
only one Style coming from Application
- Implicit style (coming from ancestors), explicit styles(directly applied), de
fault styles (theme style)
---------------------------------------------------------------------Template vs Styles
- Templates should be used to project properties from one form to another
- Styles should be used to configure the look on any form.
- Templates should not set the look propertie, only project properties which of
values and data.
- However, one can set the look related properties from templates as well.
-----------------------------------------------------------------------------------------------------------------Binding
- Async = true for not holding the thread on Waiting UI, it mean while gets th
e Fallbackvalue
------------------------------------------------------------DispatcherObject:
- thread affinity class in wpf, to implement STA,
- Only the thread that created the dispatcher may access a dispatcher object. U
I thread can only be assessed through dispatcher
- VerifyAccess and CheckAccess
--------------------------------------------------WPF Dispatcher:
- In WPF, a DispatcherObject can only be accessed by the Dispatcher it is assoc
iated with.
- The Dispatcher maintains a prioritized queue of work items for a specific thr
ead.
- UI handling class in wpf, all bg thread can push a message to dispatcher to e
xecute on ui thrad.
- dispatcher executes them based on priorities.
- its implemented using Priority queue
- There are different priorities. Normal is preety high priority.
---------------------------------------------------------------------------Freezable:
- Freezables are a class derived from Dispatcher obeject with 2 states. Unfroze
n and Frozen, when its unfrozen it behaves like any other obejct and shows threa
d affinity
- When its frozen it stops taking part in wpf notification system and its freez
es its thread affinity, upon which it can be passed to different thread.
- Its mostly used for grephics level objects.
- Graphics systems deal with many low level resources and upon changing the val
ue, those low level objects needs regeneration.
- On freezing it stops regeneration of those objects.
- not all freezable can be frozen, Check Canfreeze before freesing, to avoid in
valid operatione ex.
- Objects with Animation, sub-objects which can't be frozen, or a property set
by a dynamic resource can't be frozen.
- Once frozen it can never be unforzen, but and unfrozen clone can be created.
---------------------------------------------------------------------------Dependency Properties:
- Properties which take pare in WPF property system
- Over Dependency Object
- Traditionaly, each control lot of properties at the object instance level, mo
st of the values would remain default still an independet object would exist, th
is used to waste so much memory and space.
- In WPF, came up with idea of storing only changed values and a system to disc
over the value of the property at runtime,
- which is called WPF property system
- DPs are implemented using space data structure, (if null if it does not exist
. here default)
system properties such as themes and user preference,
just-in-time property determination mechanisms such as data binding and
animations/storyboards,
multiple-use templates such as resources and styles, or
values known through parent-child relationships with other elements in t
he element tree
self-contained validation,
default values,
callbacks that monitor changes to other properties, and
a system that can coerce property values based on potentially runtime in
formation
- The registered handle of a DP is calld DP Identifier, this can be used a para
meter to interact with WPF property system
- DP indentifier is stored as static member of the class
- We also get a CLR wrapper for DP, so rest of the system does not know about i
t.
- WPF property system have have precedence to follow, a local value has the hig
hest precedence except a running animation.
- In order, Property system coercion
- Active animations,
- Local value.
- TemplatedParent template properties.
- triggers
- property sets
- Implicit styles
- style triggers
- Template triggers
- Style setters
- Default Theme styles
- Inherited properties
- Default values from DP Metadata.
-** Dynamic resources and binding operations sets the precedence of the
location they are set.
- Clearvalue will on DP only clears the local value, so that Property system pr
ecedence can come into the play.