Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Animate Border WPF

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

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

596 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