A small tip for linear gradient brushes in WPF

Source: Internet
Author: User

Recently by the project inside the design of the control, most of the design will need to use the function of the progress bar, because the UI shape of the metamorphosis, the use of ProgressBar can not meet the needs, there is no way to achieve their own progress display. A lot of tossing and finding a good way to achieve the problem of progress display. There is no need for complex calculations, specifically to borrow linear gradient brushes.

Linear gradient brush when used to set the offset inside, you will find that it uses a relative value, that is, 0-1. In other words, no matter how long your fill is, it's a percentage to show your height, as long as you write the code like this.

Then you will see the effect is this:

It's half done.

But you will find that the smaller the offset, the higher the look inside the block, this Nima is not reversed? I started by 1-offset to achieve the reversal, but then moved the brain, found that there is absolutely no need to do so, we just a little bit more flexible, the code is written like this:

The effect is as follows:

hahaha, the effect has been reached, do not know you found no, I will startpoint and endpoint value swapped a bit, at the same time will be two gradientstop position also swapped a bit, to achieve this effect. This is just a little trick, share, welcome to shoot bricks =. =

A small tip for linear gradient brushes in WPF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.