1
votes

I am trying to use the contextmenu with menu items in the toolkit of silverlight. I am working with Silverlight 4.0 and the toolkit is 5.0 (maybe that is the problem to begin with) and it does not let me add a simple Context menu.
I add my reference to the code in the reference folder and select the DLL System.Windows.Controls.Toolkit and System.Windows.Controls.Input.Toolkit. I then add a reference in the XAML file like this:

xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"

and I have also tried like this:

xmlns:tk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"

I add a simple code like this:

<navigation:Page x:Class="SilverlightApplication6.Page1" 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:tk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
       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"
       xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"              
       d:DesignWidth="640" d:DesignHeight="480"
       Title="Page1 Page">
<Grid>
    <tk:ContextMenuService.ContextMenu>
        <tk:ContextMenu>

            <tk:Separator/>

        </tk:ContextMenu>
    </tk:ContextMenuService.ContextMenu>
</Grid>
</navigation:Page>

and I get this error:

The tag 'ContextMenu' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit'

So, I am either not adding the right reference or there is something messed up in the files or the version of the files.

1
Ignore that comment I found this might be the same issues you are running into stackoverflow.com/questions/4514388/…Bearcat9425
I did that... did not work, same message.Luis Garcia

1 Answers

4
votes

I work in Silverlight 4 as well, and I'm using the Toolkit from April 2010. It's specific for SL4, you can find it here: http://silverlight.codeplex.com/releases/view/43528

You can choose to download either the .zip or a msi. I picked the .msi, so your Toolkit will be installed in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\{release month year}\Bin, so VS will pick this up automatically. This allows you to add the reference through the interface in VS.

Add the xaml namespace like this:

xmlns:SLToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"

And finally, you can use the contextmenu:

<SLToolkit:ContextMenu>

</SLToolkit:ContextMenu>