0

I am trying to achieve Text scrolling in BusyIndicator, using the bellow XAML. I am getting exception related to accessing TargetName. Can someone assist?

Code behind

// Locate Storyboard resource
Storyboard s = (Storyboard)TryFindResource("animation");
s.Begin(bsi_Indicator);

XAML code:

<xctk:BusyIndicator IsBusy="True" x:Name="bsi_Indicator">
        <xctk:BusyIndicator.BusyContentTemplate>  
            <DataTemplate>
                    <StackPanel Margin="4">
                        <Canvas Name="canvas1" Height="32" ClipToBounds="True"  VerticalAlignment="Top">
                        <TextBlock Name="ScrollText" FontFamily="Verdana" FontSize="12" Text="{Binding Path=DataContext.WaitText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" >
                            <TextBlock.Resources>
                                <Storyboard x:Key="animation" Storyboard.TargetProperty="(Canvas.Left)" RepeatBehavior="Forever" >
                                    <DoubleAnimation Storyboard.TargetName="ScrollText" From="0" To="-50" Duration="0:0:10"  />
                                </Storyboard>
                            </TextBlock.Resources>
                        </TextBlock>
                    </Canvas>
                        <ProgressBar Value="100" Height="20"/>
                    </StackPanel>
            </DataTemplate>
        </xctk:BusyIndicator.BusyContentTemplate>

        <xctk:BusyIndicator.ProgressBarStyle>
            <Style TargetType="ProgressBar">
                <Setter Property="Visibility" Value="Collapsed"/>
            </Style>
        </xctk:BusyIndicator.ProgressBarStyle>
        <ContentControl />
    </xctk:BusyIndicator>

Error:

Additional information: 'ScrollText' name cannot be found in the name scope of 'Xceed.Wpf.Toolkit.BusyIndicator'.
Bolu
  • 8,696
  • 4
  • 38
  • 70
Jim
  • 2,760
  • 8
  • 42
  • 66

1 Answers1

0

I assume that your Storyboard is defined in the Window resources for example if that's your main control.

It can't find ScrollText because it's not in the scope of the Parent control which again might be Window it can be anything. It is also loaded in a BusyContentTemplate which might be different on how DataTemplate works with Xceed it might be lazy loaded so a possibility is that it is not there.

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    var dp = bsi_Indicator.BusyContentTemplate.LoadContent() as StackPanel;
    var canvas = dp.Children[0] as Canvas;
    var textBlock = canvas.Children[0] as TextBlock;
    var sb = textBlock.Resources["animation"] as Storyboard;
    sb.Begin(textBlock); // you can just call sb.Begin() too
}
123 456 789 0
  • 10,565
  • 4
  • 43
  • 72