Is it possible to draw polygon on ellipse in xaml?
Something like this:
<Ellipse
<Polygon Points="8,0 16,16, 0,16" Fill="Black" Margin="143,51,141,233" />
I need it because I would like to rotate an elipse. Polygon should rotate with elipse.
Put both shapes in a canvas and rotate the canvas using RotateTransform
<Canvas>
<Canvas.RenderTransform>
<RotateTransform CenterX="0" CenterY="0" Angle="45" />
</Canvas.RenderTransform>
<Ellipse />
<Polygon />
</Canvas>
Related
I currently have the following code:
<ScrollViewer DockPanel.Dock="Top">
<InkCanvas Name="InkCanvasOnImage" Height="203">
<InkCanvas.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=ZoomSlider,Path=Value}" ScaleY="{Binding ElementName=ZoomSlider,Path=Value}"></ScaleTransform>
</InkCanvas.LayoutTransform>
</InkCanvas>
</ScrollViewer>
<Slider DockPanel.Dock="Top" Name="ZoomSlider" Value="1" Minimum="0.3" Maximum="3" Height="20" />
When I adjust the slider, the entire ScrollViewer is changing sizes, and moving the slider up and down in the application. What I intended was just the image that is inside the InkCanvas to zoom in and out. Am I using the right WPF control for this, or did I mess up somewhere? My understanding is that I'm altering the scale of the InkCanvas and not the ScrollViewer Dimensions with the Slider.
Apply Scale Transformation On Image Instead Of InkCanvas
<ScrollViewer DockPanel.Dock="Top">
<InkCanvas Name="InkCanvasOnImage" Height="203">
<Image Source="AddImageSourceHere">
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=ZoomSlider,Path=Value}" ScaleY="{Binding ElementName=ZoomSlider,Path=Value}"></ScaleTransform>
</Image.LayoutTransform>
</Image>
</InkCanvas>
</ScrollViewer>
<Slider DockPanel.Dock="Top" Name="ZoomSlider" Value="1" Minimum="0.3" Maximum="3" Height="20" />
I have an InkPresenter and this image with a transparent background. I want my strokes to be drawn only in the transparent area and ignore the black border of the shape. How is it possible?
here is an example using WPF, same applies to InkPresenter, you can use InkPresenter.Clip property to define the clip region
<Border BorderBrush="Green"
BorderThickness="1"
Width="200"
Height="200">
<Grid>
<InkCanvas>
<InkCanvas.Clip>
<EllipseGeometry RadiusX="98"
RadiusY="98"
Center="100,100" />
</InkCanvas.Clip>
</InkCanvas>
<Ellipse Stroke="Blue"
StrokeThickness="2" />
</Grid>
</Border>
result
I was able to solve my problem using Opacity Mask:
<InkPresenter.OpacityMask>
<ImageBrush ImageSource="{Binding ImageMask}" />
</InkPresenter.OpacityMask>
Is possible to draw a Shape that has a background made by slanted lines?
An example with Rectangle (sorry for the image quality):
And if i want dashed lines or change the line properties (stroke, thickness..)?
You can use solution from this article http://mark-dot-net.blogspot.com/2007/06/creating-hatched-patterned-brush-in-wpf.html
<VisualBrush
x:Key="HatchBrush"
TileMode="Tile" Viewport="0,0,10,10"
ViewportUnits="Absolute" Viewbox="0,0,10,10"
ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Canvas>
<Rectangle Fill="Azure" Width="10" Height="10" />
<Path Stroke="Purple" Data="M 0 0 l 10 10" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
Just change the parameters etc. to fit your application
Usage:
<Rectangle Width="80" Height="40"
Fill="{StaticResource HatchBrush}"/>
Does this help: [WPF, C#: Draw a line onto existing bitmap in image control] or http://msdn.microsoft.com/en-us/library/ms747393.aspx
How to draw line inside circle, line will be visible only inside circle and I need to have control on line angel. Let say one circle and line inside it with angel 56. How to do this in C# WPF.
Just put an Ellipse and a Line in a Panel that lets them draw on top of each other (such as a Grid), and adjust the parameters to whatever you want.
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.LayoutTransform>
<RotateTransform Angle="56" CenterX="28" CenterY="28"/>
</Grid.LayoutTransform>
<Ellipse Height="56" Width="56" Stroke="Red" StrokeThickness="2" />
<Line X1="1" X2="55" Y1="28" Y2="28" Stroke="Red" StrokeThickness="2" />
</Grid>
If you want to do it in XAML, do it like this:
<Line X1="1" X2="55" Y1="28" Y2="28" Stroke="Red" StrokeThickness="2" >
<Line.LayoutTransform>
<RotateTransform Angle="56" CenterX="50" CenterY="50"/>
</Line.LayoutTransform>
</Line>
If you read through the respective overviews you should be able to manage: Geometry & Shapes
If I render the following:
<Grid>
<Canvas SnapsToDevicePixels="True">
<Path Fill="#FF000000" SnapsToDevicePixels="True" Data="M 0.00,0.00 L 2.50,0.00 0.00,10.00 " />
<Path Fill="#FF260014" SnapsToDevicePixels="True" Data="M 2.50,0.00 L 7.50,0.00 2.50,10.00 0.00,10.00 " />
<Canvas.RenderTransform>
<ScaleTransform ScaleX="{Binding ElementName=slider,Path=Value}" ScaleY="{Binding ElementName=slider,Path=Value}" />
</Canvas.RenderTransform>
</Canvas>
<Slider x:Name="slider" Minimum="0" Maximum="50" Value="30"/>
</Grid>
I get this result (Kaxaml):
Notice the thin white line between the two shapes. I searched around and found out this has to do with pixel alignment. I would expect that settings SnapsToDevicePixels="True" would be enough to get rid of the line, but this doesn't work!
Any ideas how to get rid of the white line?
Try turning edge aliasing on with RenderOptions, like this (see Grid properties)
<Grid RenderOptions.EdgeMode="Aliased">
<Canvas SnapsToDevicePixels="True">
<Path Fill="#FF000000" SnapsToDevicePixels="True" Data="M 0.00,0.00 L 2.50,0.00 0.00,10.00 " />
<Path Fill="#FF260014" SnapsToDevicePixels="True" Data="M 2.50,0.00 L 7.50,0.00 2.50,10.00 0.00,10.00 " />
<Canvas.RenderTransform>
<ScaleTransform ScaleX="{Binding ElementName=slider,Path=Value}" ScaleY="{Binding ElementName=slider,Path=Value}" />
</Canvas.RenderTransform>
</Canvas>
<Slider x:Name="slider" Minimum="0" Maximum="50" Value="30"/>
</Grid>
Remember that SnapsToDevicePixels only controls that individual points do not lie on fractional pixel values. For horizontal and vertical lines this is most easily observed. In your case you are seeing an entirely different problem. The edges of your shapes are anti-aliased and therefore blended with the background. Since your shapes are exactly adjacent to each other both will be blended with the white background of the window. You can try putting one shape behind the other instead:
<Canvas>
<Path Fill="#FF000000" Data="M 0.00,0.00 L 7.50,0.00 2.50,10.00 0.00,10.00 " />
<Path Fill="#FF260014" Data="M 2.50,0.00 L 7.50,0.00 2.50,10.00 0.00,10.00 " />
<Canvas.RenderTransform>
<ScaleTransform ScaleX="{Binding ElementName=slider,Path=Value}" ScaleY="{Binding ElementName=slider,Path=Value}" />
</Canvas.RenderTransform>
</Canvas>
which should render correctly. You see similar rendering errors in many vector file formats that render primarily to screen, such as SVG.
The other option would be to turn off anti-aliasing but that will make your edges jaggy which may not be what you want (anti-aliasing turned off in the upper half):