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>
Related
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>
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.
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:
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
How to achieve such effect in XAML:
<LinearGradientBrush x:Key="BrightSeparatorGradient" StartPoint="0.0, 0.5" EndPoint="1.0, 0.5">
<GradientStop Offset="0.0" Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" /> <!-- But fully transparent -->
<GradientStop Offset="0.5" Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" />
<GradientStop Offset="1.0" Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" /> <!-- But fully transparent -->
</LinearGradientBrush>
I've tried to create two brushes with appropriate color and Opacity set, respectively, to 0.0 and 1.0, but the compiler refused to take Brush as a Color (what is quite logic, on a second thought :)).
Best regards -- Spook.
I would create a MarkupExtension that takes a Color and returns the Color with the specified opacity:
public class OpacityExtension : MarkupExtension
{
private readonly Color color;
public byte Opacity { get; set; } // defaults to 0, so you don't have
// to set it for the color to be transparent
public OpacityExtension(Color color)
{
this.color = color;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return Color.FromArgb(Opacity, color.R, color.G, color.B);
}
}
And then you use it like so:
<LinearGradientBrush x:Key="BrightSeparatorGradient" StartPoint="0.0, 0.5" EndPoint="1.0, 0.5">
<GradientStop Offset="0" Color="{lcl:Opacity {StaticResource {x:Static SystemColors.ControlLightColorKey}}}" />
<GradientStop Offset=".5" Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" />
<GradientStop Offset="1" Color="{lcl:Opacity {StaticResource {x:Static SystemColors.ControlLightColorKey}}}" />
</LinearGradientBrush>
Spook,
Why the following doesn't work for you?
<LinearGradientBrush x:Key="BrightSeparatorGradient" StartPoint="0.0, 0.5" EndPoint="1.0, 0.5">
<GradientStop Offset="0.0" Color="Transparent" />
<GradientStop Offset="0.5" Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" />
<GradientStop Offset="1.0" Color="Transparent" />
</LinearGradientBrush>