Menu Bar Button

2185
7
11-05-2010 08:17 AM
JayKappy
Occasional Contributor
I am looking at a silverlight app from ESRI website.
The ShowCase example here:http://help.arcgis.com/en/webapi/silverlight/samples/TemplateGalleryWeb/start.htm

When I open in VB I see there there are a few folders added in the Solution Explorer. (Actions, Images, Themes, User Controls)
I then am looking at the code to create the button in the menu bar of the app...It seems that it is referencing the Folder "User Controls" and the xaml file "DropDownMenu" in that folder.

My question is how to I recreate this .... I Created a new folder and added a new Item (xaml file)
I copied the code from the Example into the xaml file and converted the cs to vb adn added in the xaml.vb file.
In the code below I then get these 2 errors:

Error:
1. The type 'userControls:DropDownMenu' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
2. UserControls is undeclared in prefix. Line 204, position 18


Thats the code in red below. HOW DO I DECLARE THIS AND POINT TO THE XAML FILE IN THE FOLDER? AND CLEAR THE ERRORS?

Is there something that I am missign to reference the new folder and xaml/vb files????

Any thoughts?


I would like to figure out how to use these folders and files contained within but cant figure out how to reference them.
If I can do this in my MainPage.xaml and accompannied vb file that great....any ideas how?


        <!--Menu bar-->
        <Grid Grid.Row="1" x:Name="TopMenuGrid" Background="{StaticResource BaseColor}">
            <Rectangle x:Name="BackgroundGradient" Opacity=".5" Fill="{StaticResource ReflectionGradient}" />
            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                <!-- Base layers -->
 <userControls:DropDownMenu>
 <userControls:DropDownMenu.MenuHeader>
                        <Button Margin="5,0,0,0" Cursor="Arrow">
                            <Button.Content>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{StaticResource MapStyleMenuTitle}" Foreground="White" FontWeight="Bold" />
                                    <Image Source="Images/Layers-32.png" Height="22" Margin="2,-3,-3,-3" />
                                </StackPanel>
                            </Button.Content>
                        </Button>
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
Look at how userControl was defined in your XAML namespace. There should be something like this
<xmlns:userControl="..."/>

That namespace definition must match the namespace in your DropDownMenu XAML and code-behind.
0 Kudos
JayKappy
Occasional Contributor
I added xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"
I then added the code in the MainPage.xaml
I then created two folders â??Themesâ?� and â??UserControlsâ?�
In Themes I added a new item â??Silverlight Resource Dictionaryâ?� and added the code, Changing Showcase with my project name

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/gislis2010_live;component/UserControls/DropDownMenu.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


I then created a new Silverlight User Control and called it DropDownMenu, pasting the xaml code from the example into my project.
I then converted the CS code and pasted that into the DropDownMenu.xaml.vb file

Here is the part with the Namespace
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports System.Windows.Markup
Imports System.Windows.Media


Namespace ESRI.ArcGIS.SilverlightMapApp
    ''' <summary>
    ''' Resizable and draggable custom window control
    ''' </summary>
    Public Class DropDownMenu
        Inherits ContentControl
        ''' <summary>


AS SOON AS I ADD THE CODE from the xaml.cs page I get errors telling me that:
Type ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol is not defined
Type ESRI.ArcGIS.Client.Map is not defined
Type ESRI.ArcGIS.Client.ToolKit.FeatureDataGrid is not defined
Type ESRI.ArcGIS.Client.Toolkit.MapTip is not defined
Also on the MainPage.xaml page I get the blue squiggly lines on this: xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp" with the error:
Undefined CLR Namespace. The clr-namespace URI refers to a namespace â??ESRI.ArcGIS.SilverlightMapAppâ?? that is not included in the assembly.

I just cant figure out how to get it all read properlyâ?¦There has to be something that I am missingâ?¦

Why is the code in the xaml.vb file creating the errors above...why are they now undefined?
0 Kudos
JenniferNery
Esri Regular Contributor
Sure. Look at the namespace definition of your project and your classes, they need to be "ESRI.ArcGIS.SilverlightMapApp" for this namespace to be valid in your xaml.
0 Kudos
JayKappy
Occasional Contributor
Sure. Look at the namespace definition of your project and your classes, they need to be "ESRI.ArcGIS.SilverlightMapApp" for this namespace to be valid in your xaml.


I do thank you for yoru response....and appologize for my lack of knowledge here....

Where is the namespace definition?
I am not following?

In my MainPage.xaml I have
    xmlns:UserControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"


In my DropDownMenu.xmal I have (Now blue squigly underlining)
    xmlns:local="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"


In my DropDownMenu.xaml.vb I have
    Namespace ESRI.ArcGIS.SilverlightMapApp


My project is called gislis2010_live

Getting a few errors:
The Type 'UserControls:DropDownMenu' was nto found Verify that you are not missing an assembly reference adn that all referenced assemblies have been built
0 Kudos
JenniferNery
Esri Regular Contributor
You can right-click on the Project and see "Properties", under Silverlight tab, there is Default namespace.

Also you should have something like

Imports System

Namespace ForumTest
'more code here
End Namespace



In the sample above, whatever class I create within this namespace is only accessible through "ForumTest", this must match the namespace definition you have in XAML. It should be "ESRI.ArcGIS.SilverlightMapApp" or you can update xmlns to use "ForumTest" (ForumTest is just my example, yours can be named different.
0 Kudos
JayKappy
Occasional Contributor
You can right-click on the Project and see "Properties", under Silverlight tab, there is Default namespace. 

Also you should have something like 

Imports System

Namespace ForumTest
'more code here
End Namespace



In the sample above, whatever class I create within this namespace is only accessible through "ForumTest", this must match the namespace definition you have in XAML. It should be "ESRI.ArcGIS.SilverlightMapApp" or you can update xmlns to use "ForumTest" (ForumTest is just my example, yours can be named different.



When I go into properties and the Silverlight tab I have
Assembly Name, Root Namespace, Startup Object, Xap fiel name.....
Whats the point in knowing the namespace again .... I mean aint I creating a new one? From wehat I can see its the same name as teh propject "gislis2010_live"....it just cant find teh new namespace I am trying to create


Yea I have that....in my DropDownMenu.xaml.vb file
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports System.Windows.Markup
Imports System.Windows.Media


Namespace ESRI.ArcGIS.SilverlightMapApp
    ''' <summary>
    ''' Resizable and draggable custom window control
    ''' </summary>
    Public Class DropDownMenu
        Inherits ContentControl
        ''' <summary>
        ''' Initializes a new instance of the <see cref="DropDownMenu"/> class.
        ''' </summary>
        Public Sub New()
            DefaultStyleKey = GetType(DropDownMenu)
            AddHandler Me.MouseEnter, AddressOf DropDownMenu_MouseEnter
            AddHandler Me.MouseLeave, AddressOf DropDownMenu_MouseLeave
        End Sub

' OTHER CODE

    End Class
End Namespace
0 Kudos
JenniferNery
Esri Regular Contributor
The point of ensuring namespace in the code-behind and xaml match is so you don't run into errors you were having where the control cannot be found, the namespace is not defined.

Since you have verified that namespaces match, you can check at the project references. I believe in VB there's a button to show all files. Be sure that ESRI.ArcGIS.Client.dll's were added or that they point to the proper location. When these assembly references are not resolved, you get into problems like types not defined.

I'd like to point you to this tutorial link: http://msdn.microsoft.com/en-us/vbasic/cc817878.aspx The problems you have been running into is not related to our API but to setting up projects in VB. Also, the compile errors usually provide line numbers or when you double-click on them you get pointed to the file that is causing problems. Go to the problem files, and try to solve it one piece at a time. You can identify the root of the issue by reading the errors themselves. It helps to backtrace the problem. For example, Xaml failed because code-behind failed, code-behind failed because project references were missing.
0 Kudos