Canvas to VisualBrush
29/08/2017
Aucun commentaire
For fill a Control you can use a canvas transformed to VisualBrush
If you change part of canvas you modify directly the render of VisualBrush
For this Canvas (set outside of window)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<Canvas x:Name="back" Height="12" Width="12" HorizontalAlignment="Left" Margin="-45,21,0,0" VerticalAlignment="Top" Background="Black"> <Ellipse Height="6" Canvas.Left="0" Canvas.Top="0" Width="6"> <Ellipse.Stroke> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4C4C4C" Offset="0.01" /> <GradientStop Color="White" Offset="1" /> <GradientStop Color="White" Offset="0.538" /> <GradientStop Color="#FF4C4C4C" Offset="0.472" /> </LinearGradientBrush> </Ellipse.Stroke> </Ellipse> <Ellipse Height="6" Canvas.Left="6" Canvas.Top="6" Width="6"> <Ellipse.Stroke> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4C4C4C" Offset="0.01" /> <GradientStop Color="White" Offset="1" /> <GradientStop Color="White" Offset="0.538" /> <GradientStop Color="#FF4C4C4C" Offset="0.472" /> </LinearGradientBrush> </Ellipse.Stroke> </Ellipse> </Canvas> |
Create VisualBrush in Window.Resource
1 2 3 4 |
<Window.Resources> <VisualBrush x:Key="background" Visual="{Binding ElementName=back}" /> </Window.Resources> |
And using
1 2 |
<Rectangle Fill="{StaticResource background}" Margin="39,39,0,39"/> |
If you want to specify using of this VisualBrush
Stretch= »None » | Define how the render is made |
TileMode= »Tile » | Define how the render of each object is made |
AlignmentX= »Left » | First aligment on X on render |
AlignmentY= »Top » | First aligment on Y on render |
ViewportUnits= »Absolute » | Type of viewport unit, if absolute no dependency of control, otherwise else |
Viewport= »0,0,12,12″ | According of ViewportUnit definition |
Sample
1 2 3 4 5 6 7 8 |
<VisualBrush x:Key="background" Visual="{Binding ElementName=back}" Stretch="None" TileMode="Tile" AlignmentX="Left" AlignmentY="Top" Viewport="0,0,12,12" ViewportUnits="Absolute" /> |
Result
Categories: Non classé, wpf
Commentaires récents