views:

1211

answers:

1

Hi, this is a problem that regularly arises when I write Silverlight XAML. In this case, I've made a usercontrol VerticalTabStop (code attached) that has a ToolTip attached. I instanciate a couple of my usercontrols, and then I get the debugging 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 an awful lot of these messages as I hover my mouse over the buttons. Any suggestions to what I'm doing wrong here?

Cheers

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>
+2  A: 

This is a bug in Silvelight. The way to work around it is to remove the Name attribute on the TextBlock in the Tooltip.

I presume that you have the name there for a reason, and that not being able to refer to this element from code is going to be a problem for you. As a work around for that, try replacing the tooltip xaml with this:

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

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

KeithMahoney
Thanks a bunch, I had no idea this was a bug in Silverlight, your solution did the trick :-)
niklassaers-vc