zoukankan      html  css  js  c++  java
  • silverlight 滚动文字

    <Canvas x:Name="c1" >
                            <Canvas.Triggers>
                                <EventTrigger RoutedEvent="Canvas.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard x:Name="animation" RepeatBehavior="Forever">
                                            <DoubleAnimation Storyboard.TargetName="tbnews" Storyboard.TargetProperty="(Canvas.Left)" From="100" To="-200"  Duration="0:0:20">
                                                
                                            </DoubleAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Canvas.Triggers>
                            
                        <TextBlock x:Name="tbnews" Text="{Binding txtnews}" FontSize="14" HorizontalAlignment="Left" Foreground="Yellow" >
                        <TextBlock.Effect>
                              <DropShadowEffect Color="White"   
        BlurRadius="30" Opacity="1" ShadowDepth="0"/>                
                        </TextBlock.Effect>
                        </TextBlock>
                        </Canvas>
                        <TextBlock Text="{Binding addtime}"  HorizontalAlignment="Left" FontSize="10" Foreground="Yellow">
                             <TextBlock.Effect>
                              <DropShadowEffect Color="White"   
        BlurRadius="30" Opacity="1" ShadowDepth="0"/>                
                        </TextBlock.Effect>    
                        </TextBlock>

    第二种方法

     <ListBox.ItemTemplate>
                                        <DataTemplate>

                                            <Grid x:Name="LayoutNews" >
                                                <Grid.Clip>
                                                    <RectangleGeometry x:Name="rg" Rect="0,150,100,100" />
                                                </Grid.Clip>
                                                <Canvas Width="150" x:Name="canvasNews" Background="White">
                                                    <StackPanel>
                                                        <TextBlock x:Name="tb" Margin="0,5,0,0" TextWrapping="Wrap" Width="150" Text="{Binding txtnews}" Foreground="Yellow">
                             <TextBlock.Effect>
                              <DropShadowEffect Color="White"   
        BlurRadius="30" Opacity="1" ShadowDepth="0"/>                
                        </TextBlock.Effect>
                                                        </TextBlock>
                                                        <TextBlock Text="{Binding addtime}"  HorizontalAlignment="Left" FontSize="10" Foreground="Yellow">
                             <TextBlock.Effect>
                              <DropShadowEffect Color="White"   
        BlurRadius="30" Opacity="1" ShadowDepth="0"/>                
                        </TextBlock.Effect>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </Canvas>

                                                <Rectangle Width="300" Height="1" Fill="#3E2A0C"></Rectangle>

                                            </Grid>

                                        </DataTemplate>
                                    </ListBox.ItemTemplate>

     int top = 0;
            public MainPage()
            {
                // 为初始化变量所必需
                InitializeComponent();
                AddItems();
                displaynews();
                DispatcherTimer dt = new DispatcherTimer();
                dt.Interval = new TimeSpan(0, 0, 0, 0, 100);
                dt.Tick += new EventHandler(dt_Tick);
                dt.Start();
            }
            void dt_Tick(object sender, EventArgs e)
            {
                top = top - 10;
                Canvas canvasNews = LayoutNews.FindName("canvasNews") as Canvas;
                
                canvasNews.Margin = new Thickness(0, top, 0, 0);

            }

    如果本文引用了你的文章而未注明,请及时联系我。
  • 相关阅读:
    java多线程(同步与死锁问题,生产者与消费者问题)
    剑指OFFER之跳台阶(九度OJ1388)
    剑指OFFER之二维数组中的查找(九度OJ1384)
    剑指OFFER之旋转数组的最小数字(九度OJ1386)
    我所思考的生活,致半年后的自己
    剑指OFFER之用两个栈实现队列(九度OJ1512)
    剑指OFFER之二维数组中的查找(九度OJ1384)
    剑指OFFER之重建二叉树(九度OJ1385)
    简单的客户机服务器投射模拟
    网络复习之TCP
  • 原文地址:https://www.cnblogs.com/sunxi/p/2714271.html
Copyright © 2011-2022 走看看