1

There is way to do effect (fade in > fade out > fade in) in Expression blend (wpf) on text from data?

example:

i have table (let's say SQL) with the data:

Name: Jack

Name: Jhon

Name: Jade

how can i do that Jack will display - and after 5 sec -> Jack will fade out and then Jhon will fade in.. and so on.

I know how to connect the sql and to write c# class and use it on wpf, but how can i do the effect from the example?

2 Answers 2

2

Here is an example that achieves it

A simple data model

 public class ModelList : List<string> { public ModelList() { Add("John"); Add("Jack"); Add("Sue"); } public int CurrentIndex = 0; public string CurrentItem { get { return this[CurrentIndex]; } } } 

Your Main Window

 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } void ContinueAnimation() { ModelList list = Resources["ModelList"] as ModelList; if ( list.CurrentIndex < (list.Count -1)) { list.CurrentIndex += 1; Storyboard b = Resources["FadeOut"] as Storyboard; b.Begin(); } } private void Start_Click(object sender, RoutedEventArgs e) { ContinueAnimation(); } private void FadeOut_Completed(object sender, EventArgs e) { ContinueAnimation(); } } 

Your main window xaml

<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:WpfApplication1" Title="MainWindow" Width="1000" Height="1000"> <Window.Resources> <app:ModelList x:Key="ModelList" /> <Storyboard x:Key="FadeOut" x:Name="FadeOut" Completed="FadeOut_Completed"> <DoubleAnimation Duration="0:0:0.5" Storyboard.TargetName="MyLabel" Storyboard.TargetProperty="Opacity" To="0" /> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyLabel" Storyboard.TargetProperty="Text"> <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{Binding Source={StaticResource ModelList}, Path=CurrentItem}" /> </ObjectAnimationUsingKeyFrames> <DoubleAnimation BeginTime="0:0:0.5" Duration="0:0:1" Storyboard.TargetName="MyLabel" Storyboard.TargetProperty="Opacity" To="1" /> </Storyboard> </Window.Resources> <StackPanel> <TextBlock Name="MyLabel" Width="100" Height="24" Background="AliceBlue" Text="{Binding Source={StaticResource ModelList}, Path=CurrentItem}" /> <Button Name="Start" Height="30" HorizontalAlignment="Left" Click="Start_Click"> Start </Button> </StackPanel> </Window> 
Sign up to request clarification or add additional context in comments.

3 Comments

What a beautiful. i need to learn the classes you wrote, this it's awesome.
what are the namespaces that i need for the classes ?
In my sample project I used them in WpfApplication1 namespace... what ever namespace you choose just update xmlns:app accordingly
1

If you have expression blend, you can create a storyboard and set the opacity at different times in the storyboard. When applied to your text, it will fade in and out.

You can hook into the Timeline.Completed Event and then set the text to the next person and restart the animation. I think the example on that page will help you out as well.

1 Comment

Actually, when i select from the data - it will always select one name. so i'll need to write for loop, and to do what you suggest here. i'm right? or there is way to select all the names?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.