Create a HUE color bar - silverlight

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:

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:

WPF Control OverrideMetadata: specify default value to come from resource

I would like to specify a resource as a default value for my control for the BorderBrushProperty. The reason being the brush is a LinearGradientBrush which I defined in XAML. So I'm looking for something like this in my static CTOR (3rd line):
static Gauge()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof (Gauge), new FrameworkPropertyMetadata(typeof (Gauge)));
BorderThicknessProperty.OverrideMetadata(typeof (Gauge), new FrameworkPropertyMetadata(new Thickness(16)));
BorderBrushProperty.OverrideMetadata(typeof (Gauge), new FrameworkPropertyMetadata("OuterFrameStroke"));
}
This is what my XAML looks like (in themes\generic.xaml):
<LinearGradientBrush x:Key="OuterFrameStroke" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF636060" Offset="1" />
<GradientStop Color="#FF5F5C5C" Offset="0" />
<GradientStop Color="#FFEEDEDE" Offset="0.35" />
<GradientStop Color="#FFA09595" Offset="0.705" />
</LinearGradientBrush>
Well, should have thought 2 seconds longer. Of course I can set this default property in my template
<Style TargetType="gauge:Gauge">
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AFD6" Offset="0.321" />
<GradientStop Color="#FF8399A9" Offset="0.674" />
<GradientStop Color="#FF718597" Offset="0.375" />
<GradientStop Color="#FF617584" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>

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>

LinearGradientBrush not behaving as supposed

I have a LinearGradientBrush defined for use in plotting a texture in a MeshGeometry3D, as follows. The idea is that values at the absolute ends of the brush should be plotted in Silver:
<LinearGradientBrush x:Key="GrayOmitOutOfRangeIncreasing" StartPoint="0,0.5"
EndPoint="1,0.5" >
<GradientStop Color="Silver" Offset="0.00" />
<GradientStop Color="#000064" Offset="0.00000000000000014" />
<GradientStop Color="#000091" Offset="0.043" />
<GradientStop Color="#0000BE" Offset="0.087" />
<GradientStop Color="#3C00B2" Offset="0.130" />
<GradientStop Color="#7800A5" Offset="0.173" />
... and other gradient stops...
<GradientStop Color="#FCE800" Offset="0.913" />
<GradientStop Color="#FCF200" Offset="0.957" />
<GradientStop Color="#FCFC00" Offset="0.99999" />
<GradientStop Color="Silver" Offset="0.99999979" />
<GradientStop Color="Silver" Offset="1" />
</LinearGradientBrush>
Instead, the values, which are transformed to a range between 0 and 1 before being plotted, are taking on a shading of the neighboring color, as in the picture below:
How can I get the image I want?
Look at how they're defined:
<GradientStop Color="#FCFC00" Offset="0.99999" />
<GradientStop Color="Silver" Offset="0.99999979" />
<GradientStop Color="Silver" Offset="1" />
This means that ... what, 0.001% of the mesh will be a gradient from FCFC00 to silver. That's not going to be detectable. Move the penultimate silver gradient stop to maybe 0.98 or something, and see if that gets you closer.

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

Resources