相关疑难解决方法(0)

故事板无法找到ControlTemplate元素

我创建了一些相当简单的XAML,并且它完美地运行(至少在KAXML中).从XAML中调用时,故事板运行完美,但当我尝试从外部访问它时,我得到错误:

'buttonGlow' name cannot be found in the name scope of 'System.Windows.Controls.Button'.
Run Code Online (Sandbox Code Playgroud)

我正在使用流阅读器加载XAML,如下所示:

Button x = (Button)XamlReader.Load(stream);
Run Code Online (Sandbox Code Playgroud)

并试图运行故事板:

Storyboard pressedButtonStoryboard =   
    Storyboard)_xamlButton.Template.Resources["ButtonPressed"];
pressedButtonStoryboard.Begin(_xamlButton);
Run Code Online (Sandbox Code Playgroud)

我认为问题是我动画的字段在模板中,故事板正在访问按钮.

这是XAML:

<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:customControls="clr-namespace:pk_rodoment.SkinningEngine;assembly=pk_rodoment" 
    Width="150" Height="55">
    <Button.Resources>
        <Style TargetType="Button">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="#00FFFFFF">
                            <Grid.BitmapEffect>
                                <BitmapEffectGroup>
                                    <OuterGlowBitmapEffect x:Name="buttonGlow" GlowColor="#A0FEDF00" GlowSize="0"/>
                                </BitmapEffectGroup>
                            </Grid.BitmapEffect>
                            <Border x:Name="background" Margin="1,1,1,1" CornerRadius="15">
                                <Border.Background>
                                    <SolidColorBrush Color="#FF0062B6"/>
                                </Border.Background>                                
                            </Border>                            
                            <ContentPresenter HorizontalAlignment="Center"
                                Margin="{TemplateBinding Control.Padding}"
                                VerticalAlignment="Center"
                                Content="{TemplateBinding ContentControl.Content}"
                                ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"/>
                        </Grid>
                        <ControlTemplate.Resources>
                            <Storyboard x:Key="ButtonPressed">
                                <Storyboard.Children>
                                    <DoubleAnimation Duration="0:0:0.4"
                                                  FillBehavior="HoldEnd"
                                                  Storyboard.TargetName="buttonGlow"
                                                  Storyboard.TargetProperty="GlowSize" To="4"/>
                                    <ColorAnimation Duration="0:0:0.6" …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf animation xaml

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

animation ×1

c# ×1

wpf ×1

xaml ×1