MSDN > 論壇首頁 > Windows Presentation Foundation (WPF) > Scroll text and images together question
發問發問
 

已答覆Scroll text and images together question

  • 2007年8月24日 下午 12:19Willie007 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Hi,

    i have a question regarding text and images that need to be scrolling together.

    (like a ticker tape)

     

    In the past (windows forms) is created a usercontrol that made a bitmap that consists of text and images.

    this bitmap was copied to the visible part of the usercontrol.

     

    My qs now is how to tackle this in wpf. Should i create a bitmap as in the previous version, or is the current system so better that the best way is to use elements that are moved...

     

    Regards,

     

    Willie Jan

解答

  • 2007年9月6日 上午 12:24Steve Galic - MSFT版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

     

    Are you looking for something like this:

     

    Code Snippet

    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Border BorderBrush="Red" BorderThickness="2,2,2,2" CornerRadius="15,0,15,15" Canvas.Top="50" Canvas.Left="50" ClipToBounds="True" Width="300" Height="75">

     <Canvas Canvas.Top="60" Canvas.Left="60" Height="60">
     <Canvas.RenderTransform>
       <TranslateTransform X="300"/>
     </Canvas.RenderTransform>
     <Canvas.Triggers>
       <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard>
         <Storyboard>
          <DoubleAnimation Storyboard.TargetProperty="(Canvas.RenderTransform).(TranslateTransform.X)"  To="-700" RepeatBehavior="Forever" Duration="0:0:8" />
         </Storyboard>
        </BeginStoryboard>
       </EventTrigger>
     </Canvas.Triggers>

       <TextBlock>This is my looooooooooooooooooooooooooooooooooooooong scrolling text. It goes on and on and on</TextBlock>
       <Image Canvas.Left="570" Source="c:\image.jpg"/>
     </Canvas>

    </Border>

    </Canvas>

     

     

     

所有回覆

  • 2007年8月27日 上午 08:24Yi-Lun LuoMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Hello, is this what you want?

            <ScrollViewer>

                <StackPanel>

                    <TextBlock>abc</TextBlock>

                    <Image Source="image.jpg"/>

                </StackPanel>

            </ScrollViewer>

     

  • 2007年8月29日 上午 08:14Willie007 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

     

    Hi,

     

    what I tried is using a Grid,

     

    But when the control is hosted into for example a Border Control, it will resize automatically to the measurements of the border size, and it must retain the full size...

    besides that I have to wait for the layout engine to have calculated the pixels before i can add a animation.

     

    is the scrollviewer able to get the same speed as using a grid to create a ticker tape?

    The speed of a grid running is ok.

     

    i will have a look at the scrollviewer.

     

    Thanks for your help.

  • 2007年8月29日 上午 08:30Yi-Lun LuoMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Border or Grid won't make your content scroll. If you need scrolling, you'll need a ScrollViewer. You can put your Border insider the ScrollViewer:

    <ScrollViewer>

    <Border>

    ...

    </Border>

    </ScrollViewer>

     

  • 2007年8月29日 上午 09:32Willie007 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I create a animation which scrolls the grid through the border control. with clipping turned on, it looks like a ticker tape ...

     

  • 2007年9月6日 上午 12:24Steve Galic - MSFT版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

     

    Are you looking for something like this:

     

    Code Snippet

    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Border BorderBrush="Red" BorderThickness="2,2,2,2" CornerRadius="15,0,15,15" Canvas.Top="50" Canvas.Left="50" ClipToBounds="True" Width="300" Height="75">

     <Canvas Canvas.Top="60" Canvas.Left="60" Height="60">
     <Canvas.RenderTransform>
       <TranslateTransform X="300"/>
     </Canvas.RenderTransform>
     <Canvas.Triggers>
       <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard>
         <Storyboard>
          <DoubleAnimation Storyboard.TargetProperty="(Canvas.RenderTransform).(TranslateTransform.X)"  To="-700" RepeatBehavior="Forever" Duration="0:0:8" />
         </Storyboard>
        </BeginStoryboard>
       </EventTrigger>
     </Canvas.Triggers>

       <TextBlock>This is my looooooooooooooooooooooooooooooooooooooong scrolling text. It goes on and on and on</TextBlock>
       <Image Canvas.Left="570" Source="c:\image.jpg"/>
     </Canvas>

    </Border>

    </Canvas>

     

     

     

  • 2007年9月7日 上午 07:22Willie007 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    I think steve, that's the way to go...

    I have to do some performance tests to see how it works out.

    Maybe i'm still a little affraid of all performance problems under VS 2005 with elements and moving them around

    looks like the direct-x under the new framework is doing some good job here...

     

    thanks.

  • 2007年9月10日 下午 08:12Steve Galic - MSFT版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Since the sample above is using RenderTransform you don't have to worry about triggering a layout pass every time you move the elements, so performance should be pretty good