?
Solved

Animate Border WPF

Posted on 2014-01-24
3
Medium Priority
?
351 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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