Vertical line reducing width at the both Ends - wpf

I have a requirement to draw a vertical line shown in Image attached. it has a width of say (1 px) Equal width in the middle but at the Dead ends it shoul look like getting disappeared. I tried with line and border but it does not look like getting disappeared at the dead ends.

Something like this;
<Rectangle Width="1">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="DarkGray" Offset="0.75"/>
<GradientStop Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.25"/>
<GradientStop Offset="0"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>

Could use a Rectangle with a LinearGradient as its Fill brush.

Related

WPF control that fades out any overflowing text to transparent, rather than clipping it or wrapping?

How can I create a WPF control (similar to a TextBlock) so that any overflowing text is faded out to transparent rather than simply clipping or wrapping?
I need to keep my control fixed-width, so expanding the width of the control to fit the text is not an option. I also do not want to make the text font smaller.
Not quite sure exactly what you are trying to achieve, but you could do something like this:
<TextBlock Text="Some long text here that should fade out">
<TextBlock.Foreground>
<LinearGradientBrush>
<GradientStop Offset="0" Color="Black"/>
<GradientStop Offset="0.7" Color="Black"/>
<GradientStop Offset="1" Color="Transparent"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
But your control still needs to be wide enough to accommodate all the text for it to display.
<TextBlock Text="fgdfgfdgfddgfdgdfgfdgfdgd" Width="129" TextWrapping="NoWrap">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.661,0.399" StartPoint="0.008,0.496">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#7F000000" Offset="0.803"/>
<GradientStop Color="#4C0A0909" Offset="0.95"/>
<GradientStop Color="#BF000000" Offset="0.729"/>
<GradientStop Color="#F8000000" Offset="0.699"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
The trick on the gradient is that even though all colors are all based off black, The fade is achieved through opacity of each gradient by playing with A part of RGBA, in pseudo-code:
GradientStop Color="Black" A=100%
GradientStop Color="Black" A=97% Offset="0.803"
GradientStop Color="Black" A=75% Offset="0.95"
GradientStop Color="Black" A=80% Offset="0.729"
GradientStop Color="Black" A=30% Offset="0.699"
Thanks guys, but I found the answer I needed on MSDN.

Partial-filling of a rectangle on Silverlight

I am new in Silverlight. I need to fill a rectangle partially with a SolidColorBrush (like a Bar, I need the border). With GradientBrush, the change of color is not sharp.
I can add two rectangles for this, but there has to be a better way.
Any suggestion would be appreciated.
I am using Silverlight 4.0.
Thanks for reading.
-Rakib
What about using gradient brush with gradient stops very close to each other, something like this:
<LinearGradientBrush x:Key="_backgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Yellow" Offset="0.65" />
<GradientStop Color="Blue" Offset="0.66" />
<GradientStop Color="Blue" Offset="1" />
</LinearGradientBrush>

Using Adobe Photoshop Gradients to Create Gradients in WPF

I am trying to create the same look for my screen as it appears in the image below.
Desired Look
My designer has given me a PSD file and the gradient overlay in PSD file looks like this.
PhotoShop Gradient
The color information of each gradient stop is also given at the above link.
I have spent hours trying to create the same look in WPF (sorry, i am a newbee :( ), But no luck yet? Is there a way to directly import photoshop gradients into Blend/VS2010? If not what is the best way of replicating this effect?
thanks in advance,
Sophie
In WPF you need more stops for this i think, here would be an approximation i just made:
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFAFAFB" Offset="0.027"/>
<GradientStop Color="White" Offset="0.957"/>
<GradientStop Color="#FFDCDAE4" Offset="0.547"/>
<GradientStop Color="#FFF1F1F1" Offset="0.47"/>
<GradientStop Color="#FF979797"/>
<GradientStop Color="#FFDADADA" Offset="1"/>
</LinearGradientBrush>
Refined it a bit more since the colour at the bottom becomes lighter again, so now it's 7 stops:
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0.03"/>
<GradientStop Color="White" Offset="0.944"/>
<GradientStop Color="#FFE0DFE5" Offset="0.539"/>
<GradientStop Color="#FFF1F1F1" Offset="0.47"/>
<GradientStop Color="#FF9D9CA0"/>
<GradientStop Color="#FFEBEBED" Offset="0.987"/>
<GradientStop Color="#FFF0F0F2" Offset="1"/>
</LinearGradientBrush>
What the Blend Gradient Eyedropper (thanks to Kris for mentioning its existence) created:
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF9E9DA1" Offset="0.002"/>
<GradientStop Color="#FFF7F7F7" Offset="0.028"/>
<GradientStop Color="White" Offset="0.035"/>
<GradientStop Color="#FFF1F1F3" Offset="0.472"/>
<GradientStop Color="#FFE0DFE5" Offset="0.543"/>
<GradientStop Color="#FFFAFAFB" Offset="0.952"/>
<GradientStop Color="#FFEBEBED" Offset="0.989"/>
</LinearGradientBrush>

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>

Use a LinearGradientBrush in another LinearGradientBrush?

I'm trying to use one LinearGradientBrush in the Definition of another LinearGradientBrush. But I've no idea weather this would even work, and if it works, I need to know how.
For Example:
<LinearGradientBrush x:Key="ComboBoxFocusBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFDEEB3" Offset="0"/>
<GradientStop Color="#FFFBF2CD" Offset="1"/>
<GradientStop Color="#FFFCE48A" Offset="0.5"/>
<GradientStop Color="#FFFBE388" Offset="0.75"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="FilterPopupTitleBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#B45988" Offset="0.75"/>
//Code here to use ComboBoxFocusBackgroundBrush
<GradientStop Color="#990088" Offset="0.75"/>
</LinearGradientBrush>
thanking you in anticipation for your answers
Edit:
To get things a bit more clear in the example I want to use "ComboBoxFocusBackgroundBrush" in the "FilterPopupTitleBrush" as a "template".So that I've the same color gradient in both brushes without a copy of the "<GradientStop...>"-tags
You can share the list of gradient stops between multiple brushes, like this:-
<GradientStopCollection x:Key="MyGradient">
<GradientStop Color="#FFFDEEB3" Offset="0"/>
<GradientStop Color="#FFFBF2CD" Offset="1"/>
<GradientStop Color="#FFFCE48A" Offset="0.5"/>
<GradientStop Color="#FFFBE388" Offset="0.75"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="ComboBoxFocusBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"
GradientStops="StaticResource MyGradient}" />
<LinearGradientBrush x:Key="FilterPopupTitleBrush" EndPoint="0.5,1" StartPoint="0.5,0"
GradientStops="{StaticResource MyGradient}" />
Now you can vary the EndPoint, StartPoint and other properties create different variants of the same basic gradient.
You can even supply the same set to RadialGradientBrush.
Sharing another way of doing this, you don't need to create a separate collection, you can also reuse the existing brush like
<LinearGradientBrush x:Key="FilterPopupTitleBrush" GradientStops="{Binding GradientStops, Source={StaticResource ComboBoxFocusBackgroundBrush}}"/>
This way of creating a custom brush based on existing brush will be helpful specially when you want to extend predefined themes like Telerik themes, where it would not be good approach to change the XAML from telerik.

Resources