-
-
Save Hypersapien/533d3c2475b7421282635d7ae96745ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="WPFTestApp.Stripes" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:local="clr-namespace:WPFTestApp" | |
mc:Ignorable="d" Loaded="UserControl_Loaded" > | |
<Border Name="border" BorderThickness="2" BorderBrush="Gray"> | |
<Rectangle Name="rect" Fill="{DynamicResource gradientBrush}"> | |
<Rectangle.Resources> | |
<Color x:Key="backgroundcolor">#000000</Color> | |
<Color x:Key="foregroundcolor">#FFFFFF</Color> | |
<LinearGradientBrush x:Key="gradientBrush" StartPoint="0,0" EndPoint="1,1" /> | |
<Storyboard x:Key="storyBoard" /> | |
</Rectangle.Resources> | |
<Rectangle.Triggers> | |
<EventTrigger RoutedEvent="Loaded"> | |
<BeginStoryboard Storyboard="{StaticResource storyBoard}" /> | |
</EventTrigger> | |
</Rectangle.Triggers> | |
</Rectangle> | |
</Border> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Media; | |
using System.Windows.Media.Animation; | |
namespace WPFTestApp { | |
/// <summary> | |
/// Interaction logic for stripes.xaml | |
/// </summary> | |
public partial class Stripes : UserControl { | |
public Stripes() { | |
InitializeComponent(); | |
LinearGradientBrush brush = (LinearGradientBrush)rect.Resources["gradientBrush"]; | |
Storyboard storyBoard = (Storyboard)rect.Resources["storyBoard"]; | |
Binding backbind = new Binding("backgroundcolor"); | |
Binding forebind = new Binding("foregroundcolor"); | |
for (int x = 0; x < 33; x++) { | |
string name = "GStop" + x.ToString(); | |
double offset = ((double)x * .05) - .4; | |
GradientStop gstop = new GradientStop() { Offset = offset }; | |
brush.GradientStops.Add(gstop); | |
gstop.SetValue(Control.NameProperty, name); | |
if (x % 2 == 0) { | |
BindingOperations.SetBinding(gstop, GradientStop.ColorProperty, backbind); | |
} else { | |
BindingOperations.SetBinding(gstop, GradientStop.ColorProperty, forebind); | |
} | |
DoubleAnimation ani = new DoubleAnimation() { | |
By = .2, | |
Duration = new TimeSpan(0, 0, 1), | |
RepeatBehavior = RepeatBehavior.Forever | |
}; | |
BindingOperations.SetBinding(ani, Storyboard.TargetPropertyProperty, new Binding("Offset")); | |
BindingOperations.SetBinding(ani, Storyboard.TargetNameProperty, new Binding(name)); | |
storyBoard.Children.Add(ani); | |
} | |
} | |
public Color BackGroundColor | |
{ | |
get { return (Color)rect.Resources["backgroundcolor"]; } | |
set { rect.Resources["backgroundcolor"] = value; } | |
} | |
public Color ForeGroundColor | |
{ | |
get { return (Color)rect.Resources["foregroundcolor"]; } | |
set { rect.Resources["foregroundcolor"] = value; } | |
} | |
private void UserControl_Loaded(object sender, RoutedEventArgs e) { | |
double size = (Width > Height ? Width : Height); | |
rect.Height = size; | |
rect.Width = size; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment