[英]Name cannot be found in the name scope of 'Xceed.Wpf.Toolkit.BusyIndicator'
I am trying to achieve Text scrolling in BusyIndicator, using the bellow XAML. 我正在尝试使用波纹管XAML在BusyIndicator中实现文本滚动。 I am getting exception related to accessing TargetName. 我收到与访问TargetName相关的异常。 Can someone assist? 有人可以协助吗?
Code behind 后面的代码
// Locate Storyboard resource
Storyboard s = (Storyboard)TryFindResource("animation");
s.Begin(bsi_Indicator);
XAML code: XAML代码:
<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'.
I assume that your Storyboard
is defined in the Window
resources for example if that's your main control. 我假设您的Storyboard
是在Window
资源中定义的,例如,如果这是您的主要控件。
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 . 它找不到ScrollText
因为它不在Parent控件的范围内,后者又可能是Window
它可以是任何东西 。 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. 它还加载在BusyContentTemplate
,这可能与DataTemplate
与Xceed
工作方式有所不同,它可能是延迟加载的,因此可能不存在。
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.