jpg image.
Static and Dynamic Resources
You might assume that because the previous example used a static resource it??™s immune to
any changes you make to your resource (in this case, the image brush). However, that??™s actually
not the case.
For example, imagine you execute this code at some point after the resource has been
applied and the window has been displayed:
Dim brush As ImageBrush
brush = CType(Me.Resources("TileBrush"), ImageBrush)
brush.Viewport = New Rect(0, 0, 5, 5)
This code retrieves the brush from the Window.Resources collection and manipulates it.
(Technically, the code changes the size of each tile, shrinking the happy face and packing the
image pattern more tightly.) When you run this code, you probably don??™t expect any reaction
in your user interface??”after all, it??™s a static resource. However, this change does propagate to
the two buttons. In fact, the buttons are updated with the new Viewport property setting,
regardless of whether they use the brush through a static resource or a dynamic resource.
The reason this works is because the Brush class derives from a class named Freezable.
The Freezable class has basic-change tracking features (and it can be ???frozen??? to a read-only
state if it doesn??™t need to change). What that means is whenever you change a brush in WPF,
any controls that use that brush refresh themselves automatically.
Pages:
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611