This project has moved and is read-only. For the latest updates, please go here.

XtraNavBarControl and Commands

Sep 9, 2008 at 12:08 AM
Is there a pattern on setting up commands for NavBarItemLink and dxTreeView nodes sited on there ?
I can't seem to locate anything

The following code seems to throw exceptions -
            foreach (DevExpress.XtraNavBar.NavBarGroup group in View.navBarControl1.Groups)
            {
                foreach (DevExpress.XtraNavBar.NavBarItemLink link in group.ItemLinks)
                {
                    string tag = link.Item.Tag as string;
                    DevExpress.XtraNavBar.NavBarItem item = link.Item;                   
                    if ( tag != null && tag is string )
                        WorkItem.Commands[tag].AddInvoker(item, "LinkClicked");
                }
            }

exception given below
Microsoft.Practices.CompositeUI.Services.ModuleLoadException was unhandled
  Message="Failed to load module from assembly f601fe24-4ccc-4d6e-b553-2501486bb6a0. Error was:\r\nFailed to load module from assembly Infrastructure.Layout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Error was:\r\nException has been thrown by the target of an invocation."
  Source="Infrastructure.Library"
  StackTrace:
       at SmartClient3.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.ThrowModuleLoadException(Exception innerException) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 434
       at SmartClient3.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.InitializeModuleClasses(WorkItem workItem) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 396
       at SmartClient3.Infrastructure.Library.Services.DependentModuleLoaderService.InnerLoad(WorkItem workItem, IModuleInfo[] modules) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 124
       at SmartClient3.Infrastructure.Library.Services.DependentModuleLoaderService.Load(WorkItem workItem, IModuleInfo[] modules) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 79
       at Microsoft.Practices.CompositeUI.CabApplication`1.LoadModules()
       at Microsoft.Practices.CompositeUI.CabApplication`1.Run()
       at SmartClient3.Infrastructure.Shell.ShellApplication.RunInDebugMode() in C:\home\test-code\SmartClient3\Source\Infrastructure\Shell\ShellApplication.cs:line 56
       at SmartClient3.Infrastructure.Shell.ShellApplication.Main() in C:\home\test-code\SmartClient3\Source\Infrastructure\Shell\ShellApplication.cs:line 47
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Reflection.TargetInvocationException
       Message="Exception has been thrown by the target of an invocation."
       Source="mscorlib"
       StackTrace:
            at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
            at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
            at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
            at Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.InjectProperties(IBuilderContext context, Object obj, String id)
            at Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
            at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
            at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.BuildFirstTimeItem(Type typeToBuild, String idToBuild, Object item)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.Build(Type typeToBuild, String idToBuild, Object item)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.AddNew(Type typeToBuild, String id)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.AddNew[TTypeToBuild]()
            at SmartClient3.Infrastructure.Layout.Module.Load() in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Layout\Module.cs:line 23
            at SmartClient3.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.InitializeModuleClasses(WorkItem workItem) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 389
       InnerException: System.FormatException
            Message="Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
            Source="mscorlib"
            StackTrace:
                 at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
                 at System.String.Format(IFormatProvider provider, String format, Object[] args)
                 at Microsoft.Practices.CompositeUI.Commands.Command.AddInvoker(Object invoker, String eventName)
                 at SmartClient3.Infrastructure.Layout.ShellLayoutViewPresenter.OnViewSet() in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Layout\ShellLayoutViewPresenter.cs:line 23
                 at SmartClient3.Infrastructure.Interface.Presenter`1.set_View(TView value) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Interface\Presenter.cs:line 31
                 at SmartClient3.Infrastructure.Layout.ShellLayoutView.set_Presenter(ShellLayoutViewPresenter value) in C:\home\test-code\SmartClient3\Source\Infrastructure\Infrastructure.Layout\ShellLayoutView.cs:line 31
            InnerException:

Sep 11, 2008 at 4:57 AM
Just off of the top of my head, I don't know what happens if the tag is blank here. You might want to change the line:
     if ( tag != null && tag is string )
to
     if(!String.IsNullOrEmpty(tag))

I don't believe that you need to check to see if the tag is a string since you have done a cast two lines prior and that would have thrown an exception if it wasn't a string (or couldn't be cast to a string).

If that doesn't help, perhaps you could give a slightly larger example that I could look at, I may be able to help.

dlx