已答覆 Problem with Storyboard Binding

  • 2006年10月16日 上午 10:08
     
     

    I want to implement this function:

    Display any text in an area with determined width, if the length of text is greater the the width of the area, display the text in an automatically rolling way.

     

    In Trigger of ControlTemplate, I defined an Animation. I set Animation.To binding to an element defined in ControlTemplate. (As shown in the code in red).  The code can be compiled in RC1 SDK, but an exception is thrown during running. If I set Animation.To to any integer(such as 225), the code works fine.

     

    It seems there’s some problem in Binding. Can anyone help me on this?

    The code is posted as below:

     

    <Window

      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

      xmlns:src="clr-namespace:SDKSample"

      x:Class="SDKSample.Window1"

      Title="Text Animation Examples"

      Background="LightSteelBlue"

      >

      <Window.Resources>

        <src:TextRollingPositiveConverter x:Key="TextRollingPositiveConverter"/>

       

        <ControlTemplate x:Key="CTemplateKey">

          <ScrollViewer Name ="SV" Width="300" Background="Aqua" ScrollViewer.VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">

            <TextBlock Margin="10,0,0,0" Name="MyRotatingText" FontSize="48" FontWeight="Bold" Foreground="Teal">

              This is scroll text

              <TextBlock.RenderTransform>

                <TranslateTransform x:Name="MyTranslateTransform"/>

              </TextBlock.RenderTransform>

            </TextBlock>

          </ScrollViewer>

          <ControlTemplate.Triggers>

            <DataTrigger Binding="{Binding ElementName=SV,Path=ScrollableWidth,Converter={StaticResource TextRollingPositiveConverter}}" Value="true">

              <DataTrigger.EnterActions>

                <BeginStoryboard>

                  <Storyboard>

                    <DoubleAnimation

                      Storyboard.TargetName="MyTranslateTransform"

                      Storyboard.TargetProperty="(TranslateTransform.X)"

                      From="0" Duration="0:0:10"

                      RepeatBehavior="Forever">

                      <DoubleAnimation.To>

                        <Binding ElementName="SV" Path="ScrollableWidth"/>

                      </DoubleAnimation.To>

                    </DoubleAnimation>

                  </Storyboard>

                </BeginStoryboard>

              </DataTrigger.EnterActions>

            </DataTrigger>

          </ControlTemplate.Triggers>

        </ControlTemplate>

      </Window.Resources>

     

      <StackPanel Margin="20" Background="Beige"  Height="100">

        <ContentControl Template="{StaticResource CTemplateKey}"/>

      </StackPanel>

    </Window>

所有回覆

  • 2006年10月17日 上午 12:14
     
     已答覆

    After one of the CTP releases, it was discovered that use of a Binding object in this manner would cause data corruption when the ControlTemplate is used across threads. 

    Most people never encountered any problems, because most ControlTemplate Storyboard animation only ever ran on a single thread.  However, as soon as the animation starts running on more than one thread, random object state information became corrupted on all threads.

    Because any corruption can potentially be used as a security exploit, a small runtime check was added to block this usage pattern.  This check is present in RC1, and it is why the markup above does not work.

    We hope to re-enable this usage pattern in a future release of WPF.  In the meantime, you would have to utilize the ScrollableWidth value in some other manner, one that does not require using a Binding inside a Storyboard.

  • 2006年10月18日 上午 05:19
     
     

    thank you