• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
无忧岛主
实践是检验真理的唯一标准
博客园    首页    新随笔       管理    订阅  订阅
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);

        }

如果本文引用了你的文章而未注明,请及时联系我。
posted on 2012-10-07 18:05  无忧岛主  阅读(1089)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3