在System.Windows.Style'的名称范围内找不到名称。

时间:2017-02-16 10:06:53

标签: c# wpf

因为我只能在运行时知道KeyTime,并且无法在那里进行绑定,所以我在代码中构建了故事板。它工作正常。

我对StopStoryboard有疑问。每当退出触发器发生时,我得到:

  

在System.Windows.Style'的名称范围内找不到名称。

这是我使用的代码:

private static void InjectStorybord(Hourglass originator)
{
    Storyboard sb = GetStoryboard(originator);
    originator.Resources["MainStory"] = sb;

    Binding runningBinding = GetBinding(originator);

    DataTrigger trigger = new DataTrigger() { Binding = runningBinding, Value = true };

    BeginStoryboard begineStory = new BeginStoryboard() { Storyboard = sb, Name = BEGIN_MAIN_NAME };
    begineStory.SetValue(FrameworkElement.NameProperty, BEGIN_MAIN_NAME);//Trying this to achive x:Name not helping eithre
    trigger.EnterActions.Add(begineStory);
    trigger.ExitActions.Add(new StopStoryboard() { BeginStoryboardName = begineStory.Name });


    Style beginStoryStyle = new Style(typeof(Grid));
    beginStoryStyle.Triggers.Add(trigger);


    originator.layoutRoot.Style = beginStoryStyle;
 }

1 个答案:

答案 0 :(得分:1)

尝试使用Style beginStoryStyle = new Style(typeof(Grid)); beginStoryStyle.RegisterName(BEGIN_MAIN_NAME, begineStory); beginStoryStyle.Triggers.Add(trigger); 方法

在样式中注册名称
names =  [['cat', 'fish'], ['cat'], ['fish', 'dog', 'cat'],
 ['cat', 'bird', 'fish'], ['fish', 'bird']]