Drawing Brush Alternative
I am attempting to create a brush that has segmentation.
e.g.
At first, I tried DrawingBrush but I see that is not yet supported. What would be a good alternative, which I may apply to either a rectangle or progressbar (either is fine)?
e.g.
At first, I tried DrawingBrush but I see that is not yet supported. What would be a good alternative, which I may apply to either a rectangle or progressbar (either is fine)?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Drawing Brush Alternative
For that kind of bar you can use a repeating linear gradient, something like this:
Is that what you are looking for?
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border Background="Black" Padding="2" Width="500" Height="20">
<Grid Width="{Binding Value, ElementName=progress}" HorizontalAlignment="Left">
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="175,0" MappingMode="Absolute" SpreadMethod="Repeat">
<GradientStop Offset="0" Color="#ffcca742"/>
<GradientStop Offset="0.99" Color="#ffcca742"/>
<GradientStop Offset="0.99" Color="#00cca742"/>
<GradientStop Offset="1" Color="#00cca742"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="2" VerticalAlignment="Bottom" Fill="#b0ffffff"/>
</Grid>
</Border>
<Slider x:Name="progress" Minimum="0" Maximum="496" Value="400" Width="200" VerticalAlignment="Bottom" Margin="20"/>
</Grid>
Re: Drawing Brush Alternative
Wow. That is pretty incredible. I had no idea this was possible using SpreadMode. Is there a performance trade-off between using Slider vs ProgressBar vs Rectangle vs Border if I anticipate the width updating every frame?
Thank you!
Thank you!
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Drawing Brush Alternative
Using a LinearGradientBrush with SpreadMethod wont' have any performance downside.
In this case the best option is to have a ProgressBar and include the Grid rendering the bar inside the template as the PART_Indicator element.
In this case the best option is to have a ProgressBar and include the Grid rendering the bar inside the template as the PART_Indicator element.
Who is online
Users browsing this forum: Semrush [Bot] and 89 guests