How to use Path? In particular, how to draw a cross with it?
1 answer
Here is an example with the Close button:
<Style TargetType="Button" x:Key="CloseButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Ellipse Stroke="Gray" StrokeThickness="2" Name="BG"/> <Path Stroke="Gray" StrokeThickness="2" Stretch="Fill" Name="PATH" Data="M 0 0 M 0.3 0.3 L 0.7 0.7 M 0.3 0.7 L 0.7 0.3 M 1 1"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="BG" Property="Fill" Value="Red"/> <Setter TargetName="PATH" Property="Stroke" Value="White"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> Application:
<Button Width="30" Height="30" Style="{StaticResource CloseButton}"/> We get:
In short: Path internal language defined. M means “go without drawing anything.” L means to draw. The resulting image is taken descriptive rectangle, and stretched proportionally to the entire size of the control.
In our case:
M 0 0: put an invisible point with coordinates (0, 0)M 0.3 0.3: go to the point (0.3, 0.3)L 0.7 0.7: draw a line to the point (0.7, 0.7)M 0.3 0.7: go to the point (0.3, 0.7)L 0.7 0.3: draw a line up to (0.7, 0.3)M 1 1: go to the point (1, 1)
Steps 1 and 6 are needed so that the describing rectangle does not directly adjoin the edges of the cross.
Here is a description of the entire syntax: https://msdn.microsoft.com/en-us/library/cc189041%28v=vs.95%29.aspx
- And there are no tools that visually help to draw, at least at the level of paint? - Monk
- 2@Monk Microsoft Expression Blend - PECHAILTER
- @Monk: Or checkered paper and pencil :) - VladD
- @VladD actually I already figured out before your answer. :) It is well-written here: professorweb.ru/my/WPF/graphics_and_animation/level13/13_5.php - PECHAPPER
- 2@Monk Path uses SVG notation, you can draw in any SVG editor and then just copy - Oleg Nechitaylo
|
