[DevExpress Support Team: CLONED FROM T213062: Element with the same name already exists in the scope]
In my case, the problem was x:Name attribute on dxr:RibbonGalleryBarItem within a data template.
It is a bit strange because when the "second" item was added the "first" one was supposed to be removed from the ribbon.
<dxr:RibbonPageCategory PagesSource="{Binding Selected.ContextMenu.ChildItems}"> was used and the Selected has changed. ContextMenu was constructed dynamically and different objects that could possibly be assigned to Selected could have an item that would use the same data template. If the explanation doesn't make much sense, I can probably come up with a sample project.
By the way, I'm using 15.1.5 and the name is still not shown in the exception.
An exception is raised when RibbonGalleryBarItem's name is defined within DataTemplate
Answers approved by DevExpress Support
We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.
Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.
- v15.2.4Download Official Update
- v15.1.8Download Official Update
Hello Kirill,
Would you please provide us with a simple sample where we can see a full picture of your current implementation? This will help us find the cause of the issue and suggest a more suitable solution. We are looking forward to your response.
Thanks,
Andrey
The project is based on T300335 and is a bit "bigger" than absolutely necessary. My apologies for that extra noise.
DXRibbonWindow1.xaml has a comment with "T301032" that documents the workaround. DXRibbonWindow1.xaml.cs has another similar comment that may or may not be relevant.
Hello,
I cannot replicate this problem by using version 15.1.7. Please take a moment to review the attached screencast. Probably I missed something essential.
Thanks,
Elliot
Elliot, sorry about not being clear.
To trigger the crash you have to change the font size combo box. It's not the real font size, it's just a trigger to rebuild the gallery - see DXRibbonWindow1.eFontSize_EditValueChanged (useAlpha is used to just see that the gallery was rebuilt, FontSettings = BuildGalleryPage() is the actual rebuild that triggers the crash).
Hi Kirill,
Thank you for the additional clarification. Now I see the exception.
Would you please clarify the purpose of assigning names to items in the templates. All generated bar items are added to the same namescope, so your current approach will likely cause issues in the future. To reproduce the exception, it's sufficient to add two items to the data source collection.
I am looking forward to your response.
Ivan, in the original T213062 Andrey Marten (DevExpress Support) asked how Alexander Muylaert-Gelein solved the issue. And in attempt to be helpful, I added how I solved the same exception in my case.
In my production code, the idea behind the name was to bind item's command to bar item's command, i.e.
<dxb:GalleryItem Glyph="{Binding Glyph}" Caption="{Binding Caption}" Command="{Binding DataContext.Command, ElementName=gallery}" />
Since I know that there will only be one such gallery in the ribbon at any given time, I didn't expect the exception. That's why I called the behaviour "strange". As noted in RibbonItemTemplateSelector.SelectTemplate in my sample project, the fact that the selector is called for a container that is not in any window is a bit strange too.
Bottom line: I can't even call the behaviour "a bug"; more like "warning to not use names even if you know that they are unique". It would be good if the behaviour is fixed in future versions, but it should not be a showstopper (one can use RelativeSource instead).
Hi Kirill,
It looks like the behavior in the scenario where only the one named gallery is used in the RibbonControl is incorrect. I have forwarded this ticket to our developers to research. We will contact you once we have any results.
Thanks,
Ilya