X
X
Xveeder2018-07-15 19:59:02
WPF
Xveeder, 2018-07-15 19:59:02

How to round corners on a WPF element?

Good afternoon, comrades.
The question arose, how to round the corners of the elements? Buttons, Gryds, etc.
In general, a very common task, but you can’t figure it out without half a liter.
By the way, how good is the practice to cut interfaces in Blend?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Makarenya, 2018-07-16
@Xveeder

The best way is to manually draw the element template. The same button, for example.
The first link I came across with a sane example:
https://professorweb.ru/my/WPF/Template/level17/17...
General point:
You need to specify the Template parameter for the object whose corners you want to round.
This can be done as in the example on the page through a link to StaticResource, or in place by specifying

<Button.Template>
...
</Button.Template>

The template itself is described by the <ControlTemplate TargetType="Button">. Well, or not Button, but the element that you want to issue.
Inside, you can draw the button however you want. You can <Rectangle RadiusX="10" RadiusY="10">, you can <Border CornerRadius="10">- at your discretion. Don't forget to add <ContentPresenter>to display the content of the button (its text or any other elements that should be placed on it). In reality, you will have to add coloring depending on the state later (active, cursor hovered, cursor not hovered), and possibly an animation of the transition between these states!
In order not to do it all from scratch, it is often convenient to copy the default style from the microsoft site , and then tweak it to your liking.
Blend has never been used. Still, it seemed to me more convenient to work with clean code. The whole idea of ​​the blend was, in my opinion, to put a designer behind it, and for the latter to issue blocks ready for use on it. It's useless for a programmer.

P
Pixilys, 2020-06-17
@Pixilys

Here is a solution worthy of attention and everything is clear.
https://ru.stackoverflow.com/questions/540305/visu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question