There are two ways to specify the Visual content of a VisualBrush.
Create a new Visual and use it to set the Visual property of the VisualBrush.
Use an existing Visual, which creates a duplicate image of the target Visual. You can then use the VisualBrush to create interesting effects, such as reflection and magnification.
When you define a new Visual for a VisualBrush and that Visual is a UIElement (such as a panel or control), the layout system runs on the UIElement and its child elements when the AutoLayoutContent property is set to true. However, the root UIElement is essentially isolated from the rest of the system; styles, storyboards, and external layout can't permeate this boundary. Therefore, you should explicitly specify the size of the root UIElement, because its only parent is the VisualBrush and therefore it cannot automatically size itself to the area being painted. For more information about layout in Windows Presentation Foundation (WPF), see the The Layout System.
Updates to the visual tree of a VisualBrush will not propagate if a BitmapEffect is in the brush's parent chain. You can workaround this limitation by forcing an update of the scene on the object above the effect. You can call InvalidateVisual or include an animation to force a scene update.
Freezable Features: Because it inherits from the Freezable class, the VisualBrush class provides several special features: VisualBrush objects can be declared as resources and shared among multiple objects. For more information about the different features provided by Freezable objects, see the Freezable Objects Overview.
Note: |
|---|
A
VisualBrush cannot be made read-only (frozen) when its Visual property is set to any value other than null. |