Solved

Animate Border WPF

Posted on 2014-01-24
3
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Expert Comment

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

Accepted Solution

by:
G Scott earned 0 total points
ID: 39814809
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
ID: 39827440
I just collapse and show borders as I need them.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

688 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