Using Adobe Photoshop Gradients to Create Gradients in WPF - 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>

Related

Vertical line reducing width at the both Ends

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.

How to create an array of linear gradient brushes in xaml using static resource?

I am trying to create an array of gradient brushes in xaml but I would like to point each array element back to a static resource that is the gradient brush. So, far I've been unable to achieve this. Can someone provide guidance on how I might accomplish this?
I want to add them to an x:Array but point to the resource rather than having to re-define the brushes as I've had to do here. I use the brushes in several places in addition to an array of them so I only want to define the brushes once.
<LinearGradientBrush x:Key="OrangeLinearGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFF7941D" />
<GradientStop Offset="1" Color="#FFF26522" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="RedLinearGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#F26263" />
<GradientStop Offset="1" Color="#B80303" />
</LinearGradientBrush>
<x:Array x:Key="BrushArray" Type="LinearGradientBrush">
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFF7941D" />
<GradientStop Offset="1" Color="#FFF26522" />
</LinearGradientBrush>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#F26263" />
<GradientStop Offset="1" Color="#B80303" />
</LinearGradientBrush>
</x:Array>
You may use StaticResourceExtensions:
<x:Array x:Key="BrushArray" Type="LinearGradientBrush">
<StaticResourceExtension ResourceKey="OrangeLinearGradientBrush"/>
<StaticResourceExtension ResourceKey="RedLinearGradientBrush"/>
</x:Array>

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:

Office 2010 buttons orange gradient

Someone knows which colors and offsets are used in Microsoft Office 2010 buttons (orange color).
It would be best, if You send me as answer ready XAML code for brush background of buttons.
Kind regards!
You can use my gradient generator
It takes some image and generates code for linear gradient brush. So you can use print screen button on your keyboard, than open this image in gradient generator and you will get something like that:
So, here is gradient code:
<LinearGradientBrush x:Key="orange-button_center" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Offset="0" Color="#fff1ca58" />
<GradientStop Offset="0.0153846153846154" Color="#fffdf9e8" />
<GradientStop Offset="0.0307692307692307" Color="#fffdeeb3" />
<GradientStop Offset="0.0461538461538461" Color="#fffdeca9" />
<GradientStop Offset="0.076923076923077" Color="#fffde99b" />
<GradientStop Offset="0.107692307692308" Color="#fffde690" />
<GradientStop Offset="0.123076923076923" Color="#fffde48b" />
<GradientStop Offset="0.138461538461538" Color="#fffde388" />
<GradientStop Offset="0.430769230769231" Color="#fffde388" />
<GradientStop Offset="0.461538461538462" Color="#fffce388" />
<GradientStop Offset="0.492307692307692" Color="#fffce388" />
<GradientStop Offset="0.523076923076923" Color="#fffce287" />
<GradientStop Offset="0.538461538461538" Color="#fffce387" />
<GradientStop Offset="0.569230769230769" Color="#fffce287" />
<GradientStop Offset="0.661538829230806" Color="#fffce287" />
<GradientStop Offset="0.692307692307692" Color="#fffce286" />
<GradientStop Offset="0.846153846153846" Color="#fffce286" />
<GradientStop Offset="0.861538461538461" Color="#fffce389" />
<GradientStop Offset="0.876923076923077" Color="#fffce691" />
<GradientStop Offset="0.892307692307692" Color="#fffce89b" />
<GradientStop Offset="0.923076923076923" Color="#fffceeb3" />
<GradientStop Offset="0.953846521538498" Color="#fffcf5d1" />
<GradientStop Offset="0.969231136923114" Color="#fffcf8de" />
<GradientStop Offset="0.984615752307729" Color="#fffdfcf2" />
<GradientStop Offset="1" Color="#fff5d74a" />
</LinearGradientBrush>
If gradient is too complex you can change precision to get more approximate color and less gradient stops

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