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.
Related
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.
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 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>
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>
I want to assign a resource I already have a second name, similar to using the BasedOn property of Styles. Specifically I have a brush that I use for a group of elements called ForegroundColor and I would like to use it in a control template (a ComboBox) calling it MouseOverBackgroundBrush. I would like to do something like this:
<ResourceCopy x:key="MouseOverBackgroundBrush" Value="{StaticResource ForegroundColor}" />
Is there a way to do this or is there a better way to go about this in Xaml?
This is a feature that doesn't have very good support in XAML. I believe that you'll either need to repeat yourself (and change both locations anytime you need to change the brush) or if you don't mind a bit of code behind, you can accomplish the duplication like this:
Resources["MouseOverBackgroundBrush"] = Resources["ForegroundColor"];
I don't know about how to copy a resource in xaml (can it even be done?) like you are asking ... but here is one way to accomplish what you are trying to do:
<Color x:Key="firstColor">#FFD97A7A</Color>
<Color x:Key="secondColor">#FFF4BFBF</Color>
<LinearGradientBrush x:Key="firstGradientBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource firstColor}" Offset="0"/>
<GradientStop Color="{DynamicResource secondColor}" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="secondGradientBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource firstColor}" Offset="0"/>
<GradientStop Color="{DynamicResource secondColor}" Offset="1"/>
</LinearGradientBrush>
Basically, create two different brushes based on some common colors.