An item with the same key has already been added.

3 posts, 1 answers
  1. Metin
    Metin avatar
    15 posts
    Member since:
    May 2013

    Posted 13 Aug 2013 Link to this post

    After current theme changed at runtime (by clearing the app resource dictionary and new theme's resources added)
    and roll over the menu the below exception is raised.

    An item with the same key has already been added.

    Stack trace

       konum System.Windows.ResourceDictionary.Add(String key, Object value, Boolean isKeyAType)
       konum System.Windows.ResourceDictionary.Add(String key, Object value)
       konum Telerik.Windows.Controls.Animation.AnimationManager.PrepareStoryboard(FrameworkElement target, Storyboard storyboard, AnimationSelectorBase selector, String animationName, RadAnimation animation, ControlTemplate targetControlTemplate, Boolean animateSelf)
       konum Telerik.Windows.Controls.Animation.AnimationManager.GetOrCreateStoryboard(FrameworkElement target, String animationName, Boolean animateSelf)
       konum Telerik.Windows.Controls.Animation.AnimationManager.Play(FrameworkElement target, String animationName, Action completeCallback, Boolean animateSelf, Object[] args)
       konum Telerik.Windows.Controls.RadMenuItem.OnPlacementOpened(Object sender, RadRoutedEventArgs e)
       konum Telerik.Windows.RadRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       konum Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       konum Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       konum Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
       konum Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       konum Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
       konum Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       konum Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
       konum Telerik.Windows.Controls.PopupPlacement.ChildElement_SizeChanged(Object sender, SizeChangedEventArgs e)
       konum System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e)
       konum MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)

    It is in   Telerik.Windows.Controls.Animation.AnimationManager.PrepareStoryboard

     private static void PrepareStoryboard(FrameworkElement target, Storyboard storyboard, AnimationSelectorBase selector, string animationName, RadAnimation animation, ControlTemplate targetControlTemplate, bool animateSelf)
                if (storyboard != null)
                    storyboard.Completed += new EventHandler(AnimationManager.OnStoryboardCompleted);
                    AnimationManager.SetAnimation(storyboard, animation);
                    AnimationManager.SetAnimationSelector(storyboard, selector);
                    AnimationManager.SetTargetControlTemplate(storyboard, targetControlTemplate);
                    if (animateSelf)
                        Dictionary<string, Storyboard> storyboards = AnimationManager.GetStoryboardsDictionary(target);
                        if (storyboards == null)
                            storyboards = new Dictionary<string, Storyboard>();
                            AnimationManager.SetStoryboardsDictionary(target, storyboards);
                        if (storyboards.ContainsKey(animationName))
                            storyboards[animationName] = storyboard;
                        storyboards.Add(animationName, storyboard);
                    FrameworkElement firstChild = VisualTreeHelper.GetChild(target, 0) as FrameworkElement;
                    firstChild.Resources.Add(animationName, storyboard);

    I guess it can be caused because of 

    firstChild.Resources.Add(animationName, storyboard);

    For now: i have updated the itemssource of the menu when theme is changed. But that error was not being raised at 2012 Q2 and the
    menu was working fine.

    Now I use 2013 Q1. same error happened also at 2012 Q3.

    My menu user controls' content is like below:

            <telerik:HierarchicalDataTemplate x:Key="MenuItemTemplate" ItemsSource="{Binding Items}">
                <TextBlock Text="{Binding Text}" />

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
            <telerik:RadMenu x:Name="xMenu" ItemTemplate="{StaticResource MenuItemTemplate}" ItemsSource="{Binding Items}" VerticalAlignment="Top" IsTabStop="False">
                    <Style TargetType="telerik:RadMenuItem" BasedOn="{StaticResource RadMenuItemStyle}">                    
                        <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
                        <Setter Property="IsChecked" Value="{Binding IsChecked}" />
                        <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />
                        <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
                        <Setter Property="IsTabStop" Value="False" />
                        <Setter Property="StaysOpenOnClick" Value="{Binding StaysOpenOnClick}" />
                        <Setter Property="Icon" Value="{Binding Image}" />
                        <Setter Property="Tag" Value="{Binding OriginalText}" />
                        <Setter Property="Command" Value="{Binding Command}" />
                        <Setter Property="CommandParameter" Value="{Binding}" />

    Am i missing something or is this a bug?
    Thanks for help.
  2. Answer
    Yana avatar
    4604 posts

    Posted 16 Aug 2013 Link to this post

    Hi Metin,

    This issue should be fixed in our latest internal build, could you please download it and give it a try?

    If you have any additional issues or questions, please write to us again.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Metin
    Metin avatar
    15 posts
    Member since:
    May 2013

    Posted 20 Aug 2013 Link to this post

    solved in 2013.2.724.1050
Back to Top