1

データからのテキストに対してExpressionBlend(wpf)で効果(フェードイン>フェードアウト>フェードイン)を行う方法はありますか?

例:

私はデータを含むテーブル(たとえばSQL)を持っています:

名前:ジャック

名前:ジョン

名前:翡翠

ジャックが表示されるようにするにはどうすればよいですか-そして5秒後に->ジャックがフェードアウトし、次にジョンがフェードインします..など。

SQLを接続してc#クラスを記述し、それをwpfで使用する方法を知っていますが、例からどのように効果を得ることができますか?

4

2 に答える 2

2

これはそれを達成する例です

単純なデータ モデル

 public class ModelList : List<string>
    {
        public ModelList()
        {
            Add("John");
            Add("Jack");
            Add("Sue");
        }

        public int CurrentIndex = 0;
        public string CurrentItem
        {
            get
            {
                return this[CurrentIndex];
            }
        }
    }

あなたのメインウィンドウ

      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();    
        }

    }

メイン ウィンドウの 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>
于 2012-07-31T17:29:10.700 に答える
1

Expression Blendを使用している場合は、ストーリーボードを作成し、ストーリーボードのさまざまな時間に不透明度を設定できます。テキストに適用すると、フェードインおよびフェードアウトします。

Timeline.Completedイベントにフックして、テキストを次の人に設定し、アニメーションを再開できます。そのページの例もあなたを助けると思います。

于 2012-07-31T17:00:55.093 に答える