Silverlight: "The name already exists in the tree"

This is a problem that occurs regularly when I write Silverlight XAML. In this case, I created a usercontrol VerticalTabStop (attached code) with an attached tooltip. I run a couple of my custom controls and then get a debug window and the following error:

Line:52 Error: Unhandled Error in Silverlight 2 Application Code: 2028 Category: ParserError Message: The name already exists in the tree: AltLabel. File: Line: 0 Position: 0 

I get a lot of these messages when I hover over the buttons. Any suggestions on what I'm doing wrong here?

Greetings

 Nik <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="SLEntityPresenterWebPart.VerticalTabStop" d:DesignWidth="20" d:DesignHeight="27"> <Grid x:Name="LayoutRoot"> <StackPanel> <Canvas x:Name="TabStopCanvas" Height="27" Width="20"> <ToolTipService.ToolTip> <TextBlock x:Name="AltLabel" Text="Substitute me"/> </ToolTipService.ToolTip> <Image x:Name="IconImg" Canvas.Left="7" Canvas.Top="9" Width="26" Height="26" Source="Contact.png" Canvas.ZIndex="5" Margin="0,-9,0,0" RenderTransformOrigin="0.5,0.5"> <Image.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="0.85" ScaleY="0.85"/> <SkewTransform/> <RotateTransform/> <TranslateTransform X="0"/> </TransformGroup> </Image.RenderTransform> </Image> <Image Source="stop.png" Margin="3,0,0,0"/> </Canvas> </StackPanel> </Grid> </UserControl> 
+4
source share
4 answers

This is a mistake in Silvelight. A way around it is to remove the Name attribute in the TextBlock in the tooltip.

I assume that you have a name for some reason, and that inability to refer to this element from the code will be a problem for you. To do this, try replacing the xaml prompt as follows:

 <ToolTipService.ToolTip> <ToolTip x:Name="AltLabel" Content="Substitute me" /> </ToolTipService.ToolTip> 

Now you can jump to the text by executing AltLabel.Content. If this does not solve your problem, let me know.

+5
source

Silverlight 4 has a very similar error. If you create user controls, usually:

 <UserControl xmlns:MyNameSpace="clr-namespace:MyNameSpace" x:Class="MyNameSpace.MyClass" x:Name="userControl" ... /> 

Then, if you add 2 untitled controls to xaml code (with preview):

 <MyNameSpace:MyClass ... /> <MyNameSpace:MyClass ... /> 

There will be an exception "Name already exists in the tree: userControl". This is because Silverlight cannot find the name (unnamed [MyClass]) and looks at UserControl, where it detects "userControl" twice.

One solution is to give some controls to the controls:

 <MyNameSpace:MyClass x:Name = "MyControl1" ... /> 

Or initialize this control from code:

 MyClass control = new MyClass(); SomeGrid.Children.Add(control); 
+10
source

I struggled with the same message yesterday ... ParserError - the name already exists in the tree: blah

In my case, the problem was that somehow a link was added ... to myself. (The project DLL in the project manages its own bin / debug folder). Removing this help fixed the problem.

This error message seems to be too vague.

+1
source

Try removing any name like "x: Name =" TabStopCanvas "on the stack panel", this worked for me.

+1
source

All Articles