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
Solved

Animate Border WPF

Posted on 2014-01-24
3
347 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 49
VB.net Facial recognition software (time and attendance) 6 60
System.net.Sockets Error 5 26
Need syntax help building hyperlink 2 22
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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