This is a migrated thread and some comments may be shown as answers.

An item with the same key has already been added.

2 Answers 146 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Metin
Top achievements
Rank 1
Metin asked on 13 Aug 2013, 01:26 PM

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;
                        return;
                    }
                    storyboards.Add(animationName, storyboard);
                    return;
                }
                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:

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

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
        <telerik:RadMenu x:Name="xMenu" ItemTemplate="{StaticResource MenuItemTemplate}" ItemsSource="{Binding Items}" VerticalAlignment="Top" IsTabStop="False">
            <telerik:RadMenu.ItemContainerStyle>
                <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}" />
                </Style>
            </telerik:RadMenu.ItemContainerStyle>
        </telerik:RadMenu>
    </Grid>

Am i missing something or is this a bug?
Thanks for help.

2 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 16 Aug 2013, 12:12 PM
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.

Regards,
Yana
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
0
Metin
Top achievements
Rank 1
answered on 20 Aug 2013, 04:46 PM
solved in 2013.2.724.1050
Tags
Menu
Asked by
Metin
Top achievements
Rank 1
Answers by
Yana
Telerik team
Metin
Top achievements
Rank 1
Share this question
or