views:

181

answers:

2

Hello,

I want to draw some circles in another circle like this:

alt text

Is there a way to tell a RadialGradientBrush not to use gradients but just fixed colors, so I can achieve this? Thanks for any hint!

(I guess this could be easily done using a DrawingBrush, I'm just wondering whether this could also be done using a RadialGradientBrush)

+5  A: 

If you really, really want to do this, you can repeat the colors that you want at the offsets that you want.

For example:

            <RadialGradientBrush>
                <GradientStop Offset="0" Color="Black" />
                <GradientStop Offset="0.25" Color="Black" />
                <GradientStop Offset="0.25" Color="Red" />
                <GradientStop Offset="0.75" Color="Red" />
                <GradientStop Offset="0.75" Color="Salmon" />
                <GradientStop Offset="1" Color="Salmon" />
            </RadialGradientBrush>

That way, it will fill Black to Black from 0 to 0.25, Red to Red from 0.25 to 0.75, and Salmon to Salmon from 0.75 to 1.0.

Since the offsets match, there is no "room" for the Gradient to blend.

Wonko the Sane
Thanks for that hint, works great! The size / length / width.. of the gradients is relative, is there a way to specifiy it in device independent units, e.g. the black circle shall be 30 units?
stefan.at.wpf
Ok theres Brush.MappingMode and you can set it to absolute, but I just don't get it how to work with it... Could someone please post some example code? Thanks!
stefan.at.wpf
See next answer, for formatting reasons (and feel free to select one as The Answer). :)
Wonko the Sane
+1  A: 

If you are trying to make a "bullseye" of absolute sizes, consider overlaying Ellipses in a grid instead of trying to use a brush.

<Grid>
    <Grid.Resources>
        <Style TargetType="{x:Type Ellipse}">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
        </Style>
    </Grid.Resources>
   <Ellipse Width="100" 
            Height="100"
            Fill="Salmon" />
   <Ellipse Width="50" 
            Height="50"
            Fill="Red" />
   <Ellipse Width="25" 
            Height="25"
            Fill="Black" />
</Grid>

Since they are all in the same grid (column and row are both 0 by default, but you could set them), and have their horizontal and vertical alignments set to stretch, they will simply overlap. Be sure to put the biggest one first, of course.

Wonko the Sane
Thank you again for your reply! Still wondering how the absolute Brush.MappingMode works. Guess I'll make a new post for that. Oh and I will select one solution as answer, thanks!
stefan.at.wpf
MappingMode is for the StartPoint and EndPoint.See http://msdn.microsoft.com/en-us/library/system.windows.media.gradientbrush.mappingmode.aspx
Wonko the Sane
ah, thanks for the hint!
stefan.at.wpf