Solved

Animate Border WPF

Posted on 2014-01-24
3
342 Views
Last Modified: 2014-02-02
So, I added a striped border to a rectangle from the code behind

 
   Dim myBrush As New LinearGradientBrush()
    myBrush.GradientStops.Add(New GradientStop(Colors.DeepPink, 0.0))
    myBrush.GradientStops.Add(New GradientStop(Colors.DeepPink, 0.5))
    myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 0.5))
    myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 1.0))
    'myBrush.RelativeTransform = ScaleTransform.ScaleXProperty
    Dim scale As New ScaleTransform(0.1, 0.1)
    myBrush.RelativeTransform = scale
    myBrush.SpreadMethod = GradientSpreadMethod.Repeat
    rect0.Fill = New SolidColorBrush(Colors.LightCoral)
    theBorder.BorderBrush = myBrush

Open in new window


I want to animate this so it appears to be moving or rotating. I have seen quite a few examples on SO using XAML, but i want to do it purely using code. Can someone help me out with this? Thanks for any input you may have on this; I truly appreciate it.
0
Comment
Question by:G Scott
  • 2
3 Comments
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Can you post the links to the XAML examples you found?
0
 
LVL 1

Accepted Solution

by:
G Scott earned 0 total points
Comment Utility
The animated borders are collapsed.  But this worked.

<UserControl x:Class="UserControl1"
             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" 
             mc:Ignorable="d" Height="148" Width="149">
    <UserControl.Resources>

        <LinearGradientBrush x:Key="_brush" SpreadMethod="Repeat">

            <LinearGradientBrush.RelativeTransform>
                <ScaleTransform ScaleX="0.1" ScaleY="0.1" ></ScaleTransform>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Offset="0.0" Color="Blue" />
            <GradientStop Offset="0.5" Color="Blue" />
            <GradientStop Offset="0.5" Color="Red" />
            <GradientStop Offset="1" Color="Red" />

            <LinearGradientBrush.Transform>

                <TransformGroup x:Name="_tranformGroup">

                    <TranslateTransform X="100" />

                </TransformGroup>
            </LinearGradientBrush.Transform>
        </LinearGradientBrush>

        <Style x:Key="_border" TargetType="{x:Type Border}">
            <Setter Property="BorderBrush" Value="{StaticResource _brush}"/>
            <Setter Property="BorderThickness" Value="3"/>
            <!--<Setter Property="CornerRadius" Value="40,40,40,40"/>-->
            <Style.Triggers>
                <Trigger Property="IsVisible" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation 
                                   
                                    Storyboard.TargetProperty="BorderBrush.Transform.X"  
                                    From="0" To="800"  
                                    Duration="0:0:10"  
                                    RepeatBehavior="Forever" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid Margin="0,0,0,0">
        <Rectangle Fill="Yellow" HorizontalAlignment="Left" Height="147" Stroke="Black" VerticalAlignment="Top" Width="149" Name="wholecolor"/>
        <Label Content="MLD31A" VerticalAlignment="Top" FontSize="30" Margin="0,-7,25,0" Name="lblMold" x:FieldModifier="public"/>
        <Label Content="5053962" Margin="0,27,0,0" VerticalAlignment="Top" Name="lblTool" x:FieldModifier="public" FontSize="22"/>
        <Label Content="2324660-5B8" Margin="0,54,0,0" VerticalAlignment="Top" Name="lblJCI" x:FieldModifier="public" FontSize="13"/>
        <Label Content="CL34 16243A53 AA35B8" Margin="0,70,0,53" Name="lblCust" x:FieldModifier="public" FontSize="13"/>
        <Label Content="1800/1756/12" Margin="0,87,0,0" VerticalAlignment="Top" Name="lblNumbers" x:FieldModifier="public" FontSize="13"/>
        <Label Content="M000000006090010" Margin="0,105,0,0" VerticalAlignment="Top" Name="lblOrder" x:FieldModifier="public" FontSize="13"/>
        <Label Content="MC Wait For Mold Chg" Margin="0,122,0,-1" VerticalAlignment="Top" Name="lblStatus" x:FieldModifier="public" FontSize="13"/>
        <Border BorderBrush="White" Name="overBorder" x:FieldModifier="public" BorderThickness="1" HorizontalAlignment="Left" Height="147" VerticalAlignment="Top" Width="149" Visibility="Collapsed"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="99,39,0,0" VerticalAlignment="Top" Width="50" Name="lblTimer" FontSize="8" HorizontalContentAlignment="Right"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="99,28,0,0" VerticalAlignment="Top" Width="50" x:Name="lblTotal" FontSize="8" HorizontalContentAlignment="Right"/>
        <Border Width="148" Height="149"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
                Visibility="collapsed"
                x:FieldModifier="public"
            Style="{StaticResource _border}" Margin="0,-1,1,0" Name="SpinnerBorder" >
            <Border.BorderBrush>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Offset="0" Color="Red"/>
                    <GradientStop Offset="0.5" Color="Red"/>
                    <GradientStop Offset="0.5" Color="White"/>
                    <GradientStop Offset="1" Color="White"/>

                    <LinearGradientBrush.RelativeTransform>
                        <ScaleTransform ScaleX="0.1" ScaleY="0.1"/>
                        
                    </LinearGradientBrush.RelativeTransform>
                </LinearGradientBrush>
                <!--<LinearGradientBrush SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Color="Blue" Offset="1"/>
                    <GradientStop Color="Red" Offset="0.5"/>
                    <GradientStop Color="Blue" Offset="0.5"/>
                    <GradientStop Color="Red"/>
                </LinearGradientBrush>-->
            </Border.BorderBrush>
        </Border>
        <Border Width="148" Height="149"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
                Visibility="Collapsed"
                x:FieldModifier="public"
            Style="{StaticResource _border}" Margin="0,0,1,-1" Name="SpinnerBorder2" >
            <Border.BorderBrush>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Offset="0" Color="Blue"/>
                    <GradientStop Offset="0.5" Color="Blue"/>
                    <GradientStop Offset="0.5" Color="White"/>
                    <GradientStop Offset="1" Color="White"/>

                    <LinearGradientBrush.RelativeTransform>
                        <ScaleTransform ScaleX="0.1" ScaleY="0.1"/>
                    </LinearGradientBrush.RelativeTransform>
                </LinearGradientBrush>
                <!--<LinearGradientBrush SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Color="Blue" Offset="1"/>
                    <GradientStop Color="Red" Offset="0.5"/>
                    <GradientStop Color="Blue" Offset="0.5"/>
                    <GradientStop Color="Red"/>
                </LinearGradientBrush>-->
            </Border.BorderBrush>
        </Border>
        <Border Width="148" Height="149"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
                Visibility="Collapsed"
                x:FieldModifier="public"
            Style="{StaticResource _border}" Margin="0,0,1,-1" Name="SpinnerOverrun" >
            <Border.BorderBrush>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Offset="0" Color="Black"/>
                    <GradientStop Offset="0.5" Color="Black"/>
                    <GradientStop Offset="0.5" Color="White"/>
                    <GradientStop Offset="1" Color="White"/>

                    <LinearGradientBrush.RelativeTransform>
                        <ScaleTransform ScaleX="0.1" ScaleY="0.1"/>
                    </LinearGradientBrush.RelativeTransform>
                </LinearGradientBrush>
                <!--<LinearGradientBrush SpreadMethod="Repeat">
                    <LinearGradientBrush.Transform>
                        <TranslateTransform X="100"/>
                    </LinearGradientBrush.Transform>
                    <GradientStop Color="Blue" Offset="1"/>
                    <GradientStop Color="Red" Offset="0.5"/>
                    <GradientStop Color="Blue" Offset="0.5"/>
                    <GradientStop Color="Red"/>
                </LinearGradientBrush>-->
            </Border.BorderBrush>
        </Border>
    </Grid>
</UserControl>

Open in new window

0
 
LVL 1

Author Closing Comment

by:G Scott
Comment Utility
I just collapse and show borders as I need them.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now