Applying LinearGradientBrush to Path - wpf

Path with LinearGradientBrush:
<Path Data="M76,261 C273,301 166.53234,85.564862 274.5,301.5"
HorizontalAlignment="Left"
Height="148.664"
Margin="76,203.836,0,0"
Stretch="Fill"
VerticalAlignment="Top"
Width="323.5"
StrokeThickness="10">
<Path.Stroke>
<LinearGradientBrush EndPoint="0.05,0.0"
StartPoint="0.0,0.0"
SpreadMethod="reflect">
<GradientStop Color="Blue" Offset="0.0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Path.Stroke>
</Path>
How to apply GradientBrush to Path so that transition lines (gradient stops) are perpendicular to tangent to Path at every point of Path?
Something like this (i'm not a pro in Photoshop):

Related

Foreground colour of textblock based on position of part of the letter

A Mars bar challenge at work is that using Xaml only, make the following text of a text block gray by default. But, from half way through the letter "e" and to half way to last character "1" make the colour red.
The text is "Item 1". So, "I" and "t" all gray, but the first half of "e" red, all of "m" red and then half of "1" red and the last half of "1" gray.
I have no idea about this one.
Were you thinking about something like this?
<TextBlock FontSize="72">
<Run Foreground="Gray" Text="It" /><Run Text="e">
<Run.Foreground>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="Gray" Offset="0"/>
<GradientStop Color="Gray" Offset="0.5" />
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush>
</Run.Foreground>
</Run><Run Text="m" Foreground="Red" /><Run Text=" 1">
<Run.Foreground>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="Red" Offset="0"/>
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Gray" Offset="0.5" />
<GradientStop Color="Gray" Offset="1" />
</LinearGradientBrush>
</Run.Foreground>
</Run>
</TextBlock>
Result:

Progressbar showing different Styles

I have two solutions targeting the same 4.5 framework. Both projects uses the same version of dlls. But one is showing a progressbar without any effect. I just copied and pasted the code from one to another. One is with glossy effect and having animations in it but another is just static. What's wrong with it?
<ProgressBar HorizontalAlignment="Left" Height="30" Margin="3,0,0,0" Foreground="#FF007B00" Grid.Column="1" VerticalAlignment="Center" Width="176" Opacity="0.9" BorderThickness="0" Value="80">
<ProgressBar.Background>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="#FFBABABA" Offset="0"/>
<GradientStop Color="#FFC7C7C7" Offset="0.014"/>
<GradientStop Color="#FFE63B09" Offset="1"/>
</LinearGradientBrush>
</ProgressBar.Background>
</ProgressBar>

Create a HUE color bar

I'm creating a color picker and I am at a stage where I need to create a HUE color bar:
One way to create it would be through gradient stops in XAML. For example:
<Rectangle Width="50" Height="100">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0.025" EndPoint="0.5,1" >
<GradientStop Color="#FFFF0000" />
<GradientStop Color="#FEFFFF00" Offset="0.15" />
<GradientStop Color="#FE00FF00" Offset="0.3" />
<GradientStop Color="#FE00FFFF" Offset="0.45" />
<GradientStop Color="#FE0000FF" Offset="0.6" />
<GradientStop Color="#FEFF00FF" Offset="0.85" />
<GradientStop Color="#FFFF0000" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
The above will generate:
However, I am not sure whether the stops are correct.
Is there a convention on how to generate such a bar? Any advice would be highly appreciated.
Best Regards,
Casey
It looks like your 2nd last stop is at a different interval (+0.25) to the previous ones (+0.15). You basically want the same gap between all stops to get the same effect (that colour bar is just a linear distribution).
Try this instead:
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1.0" >
<GradientStop Color="#FFFF0000" />
<GradientStop Color="#FEFFFF00" Offset="0.167" />
<GradientStop Color="#FE00FF00" Offset="0.333" />
<GradientStop Color="#FE00FFFF" Offset="0.5" />
<GradientStop Color="#FE0000FF" Offset="0.667" />
<GradientStop Color="#FEFF00FF" Offset="0.833" />
<GradientStop Color="#FFFF0000" Offset="1.0" />
</LinearGradientBrush>
</Rectangle.Fill>
Which looks like:

Is it possible to apply Gradient to a Background Image in Silverlight?

I want to apply some gradient to my image how can I achieve that?
Thanx
You could host your image within a Border, applying the gradient to the border background:
<Border>
<Border.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Red" Offset="0" />
<GradientStop Color="Blue" Offset="1" />
</LinearGradientBrush>
</StackPanel.Background>
<Image Source=..your image source .." />
</Border>
This assumes that your image has some opaque regions which will show the gradient beneath it.
In the gradient you can use one or more colours. Any it is very easy to set the gradient using either VS2010 or expression blend. The following is the sample code of a two-colour gradient with blue and white.
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform> <CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="-90"/>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FFB6D3F9"/>
<GradientStop Color="#FFFDFDFD" Offset="1"/>
</LinearGradientBrush>

Cursor on Path doesn't appear in SilverLight

I am trying to draw a circle with a glass effect using Alpha. I am successful in creating that by using the below XAML. The cursor changes to Hand for the Ellipses, but it doesn't affect Path. Basically, I want to show "hand" cursor wherever the mouse appears over the circle. I hope this is not a known issue and I am missing something small. Any help is really appreciated.
<Ellipse Cursor="Hand"
Width="200"
Height="200"
Fill="#C42222" Canvas.Left="0" Canvas.Top="0" />
<Ellipse Cursor="Hand" Width="200" Height="200" Canvas.Left="0" Canvas.Top="0">
<Ellipse.Fill>
<RadialGradientBrush GradientOrigin="0.3,0.7">
<GradientStop
Offset="0"
Color="#00000000" />
<GradientStop
Offset="1"
Color="#66000000" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Path Cursor="Hand" Stretch="Fill" Height="114.598" Width="198.696" Data="M98.388435,-1.3301961 C98.388435,-1.3301961 117.1151,-3.094949 141.69321,8.1370029 C156.42262,14.868201 167.67375,23.694145 175.66234,33.657074 C183.67349,43.648144 181.90166,37.8708 191.90166,58.8708 C201.90166,79.870796 199.16658,89.212738 199.13568,92.90377 C198.77556,135.92146 175.45959,97.59124 156.75465,81.024025 C140.98892,67.060104 117.41241,64.357407 114.41241,64.357407 C111.4124,64.357407 83.061241,60.114159 63.061195,71.114143 C43.061146,82.114136 39.637829,86.429352 22.999804,100.99996 C6.5005584,115.44904 2.9997537,112.99996 2.9997537,112.99996 C2.9997537,112.99996 -1.1832786,97.194221 1.9997513,81.999893 C7.2054667,57.150185 13.999762,47.999939 17.999771,42.999943 C21.999781,37.99995 29.935833,23.400871 54.053131,10.21261 C78.91642,-3.3835876 98.388435,-1.3301961 98.388435,-1.3301961 z">
<Path.Fill>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#55FFFFFF" Offset="0"/>
<GradientStop Color="#11FFFFFF" Offset="0.5"/>
<GradientStop Color="#00FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Path.Fill>
</Path>
I want to show "hand" cursor wherever the mouse appears over the circle.
The hand cursor appears in my testing of your Path when the mouse is over the path. However perhaps the clue might be in your description above. The Path doesn't describe a circle more like a crescent. Add Stroke="Black" StrokeThickness="1" to the path so that you can see its outline and test that the cursor does actually work.
The other possiblity is in your actual Xaml that there is something else that has a hight z-index or appears later in the Xaml document order that overlays the Path.

Resources