Create custom "+" button in WPF

I am trying to create a custom plus button in WPF. I only need the + character, but I will not be able to get the Path data variables only in order. I looked at the Path syntax, but I still have problems.

This is what I have so far, but it is too large. I need a smaller, more proportional button:

<Path Stretch="Fill" Opacity="1" x:Name="path" StrokeThickness="10" RenderTransformOrigin="0.5,0.5" Margin="39,56.75,39,65.25" Data="M0,5L10,5 M5,5L5,1z" > 

Can someone tell me what I'm wrong here?

thanks

+4
source share
5 answers

Try it for the way -

 <Path Stretch="Fill" Fill="Black" Stroke="{x:Null}" StrokeThickness="0.5" Data="M3.875,0 L5.125,0 5.125,3.875 9,3.875 9,5.125 5.125,5.125 5.125,9 3.875,9 3.875,5.125 0,5.125 0,3.875 3.875,3.875 3.875,0 z" /> 
+3
source

You can use a Data property like this

 <Button> <Path Data="M0.5,0 L0.5,1 M0,0.5 L1,0.5" StrokeThickness="4" Stretch="Fill" Stroke="Red" /> </Button> 

Looks like this

enter image description here

Edit
If you want the line borders to reach the edges of the Button , you can set

 StrokeEndLineCap="Square" StrokeStartLineCap="Square" 
+7
source

I know that you are trying to use a drawing path and would probably like a solution for this. The solution is likely to be useful for your work in the future. But here is an alternative to this particular button, which may be preferable to the solution you ask.

I am trying to create a custom plus button in WPF

Since there is no plus button, everything you do will of course be normal. However, you do not need to completely reinvent the wheel. There are + icons that are already in use on Windows.

If your application does not have a fully customizable user interface, it is recommended that you reuse controls and images to ensure an even user experience.

To learn how to get these existing icons, check this answer: Default icons for Windows applications?

The answer relates to the Zip file that is installed using Visual Studio. From this zip file check this icon:

VS2010ImageLibrary / _Common Elements / Actions / Add.png

"Add" icons

There are other “Add” icons in the section:

VS2010ImageLibrary / Actions / png_format / WinVista
VS2010ImageLibrary / Objects / png_format / WinVista p>

"Plus" icon"Add Category" icon"Add File" icon

To use the image on your button:

+7
source

I know this seems silly, but how easy is it to use a TextBlock containing a large + character?

+5
source

For anyone who discovers this page, the following Path:

  <Path x:Name="ButtonPath" Margin="1" Stroke="Gray" StrokeThickness="1" StrokeStartLineCap="Square" StrokeEndLineCap="Square" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center" > <Path.Data> <PathGeometry> <PathGeometry.Figures> <PathFigure StartPoint="0,100"> <LineSegment Point="0,-100"/> </PathFigure> <PathFigure StartPoint="100,0"> <LineSegment Point="-100,0"/> </PathFigure> </PathGeometry.Figures> </PathGeometry> </Path.Data> </Path> 

gives me the plus button shown in this snapshot of my program Plus SnapShot button

0
source

Source: https://habr.com/ru/post/1369538/


All Articles