在'Xceed.Wpf.Toolkit.BusyIndicator'的名称作用域中找不到名称
本文关键字:作用域 找不到 Toolkit Xceed Wpf BusyIndicator | 更新日期: 2023-09-27 18:11:39
我试图在BusyIndicator中实现文本滚动,使用下面的XAML。我得到异常有关访问TargetName。有人能帮忙吗?
背后的代码// Locate Storyboard resource
Storyboard s = (Storyboard)TryFindResource("animation");
s.Begin(bsi_Indicator);
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>
错误:Additional information: 'ScrollText' name cannot be found in the name scope of 'Xceed.Wpf.Toolkit.BusyIndicator'.
我假设您的Storyboard
是在Window
资源中定义的,例如,如果这是您的主要控制。
它找不到ScrollText
,因为它不在父控件的范围内,这再次可能是Window
,它可以是任何。它也加载在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
}