I have a Rectangle with the following XAML:
<Rectangle x:Name="ActiveIndex" Width="100" Height="15" Margin="50,165,50,20">
<Rectangle.Fill>
<LinearGradientBrush>
<GradientStop Color="#6FFDFD" Offset="0.0" />
<GradientStop Color="#0D00F9" Offset="1.0" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
I need a code solution which when given the Input Offset from 1 to 100 can find the Color from ActiveIndex.
Currently I am using an another bound Rectangle with a Viewbox to Show the Color by Setting the Viewbox left value to suit the Offset. This Approach does not let get the Color as the brush is a Visual Brush.
<Rectangle x:Name="ActiveIndexColor" Width="100" Height="15" Margin="0,180,0,0" Visibility="Visible">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=ActiveIndex}"
ViewboxUnits="RelativeToBoundingBox"
Viewbox="0.0000001,0.0000001,0.0000001,0.0000001">
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
Something like...
RedColorYouWant = Offset * 0D + (1 - Offset) * 6F
GreenColorYouWant = Offset * 00 + (1 - Offset) * FD
BlueColorYouWant = Offset * F9 + (1 - Offset) * FD
maybe ?
Offset being a value between 0 and 1..
Thanks franssu for the beautiful idea!
To suit my offset I wrote my code as follows:
int red = ((offset * 13) + ((100 - offset) * 111)) / 100;
int green = ((offset * 0) + ((100 - offset) * 253)) / 100;
int blue = ((offset * 249) + ((100 - offset) * 253)) / 100;
Color color = (Color)ColorConverter.ConvertFromString("#" + red.ToString("x2") + green.ToString("x2") + blue.ToString("x2"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.