• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


wpf UserControl

  • Filter
  • Time
  • Show
Clear All
new posts

    wpf UserControl


    I would like to add a wpf User Control to my project.

    Using VS 2015 I can edit the NinjaTrader.custom.csproj and add such a control from the wizard. Using Visual Studio the build will go through with no error.

    When I then try to compile this from within NT8 I get errors and the code cannot be compiled.
    Here a typical error.

    NinjaScript File Error Code Line Column
    UserControl2.cs The type 'NinjaTrader.Custom.Strategies.UserControl2' already contains a definition for 'button' CS0102 11 49

    Problem is probably related to the fact that VS compiles xaml files to a Page. I am not sure how the NT8 works.
    Please give instructions on how to compile.


    Hello Andreas,

    Creating a custom control would be general C# and would not be specific to NinjaScript.

    This is outside of what is supported by NinjaTrader Support, however, NinjaTrader_Jesse was kind enough to put together an example for another forum member.


    This thread will remain open for any community members that would like to assist.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service


      Hello ChelseaB,

      thank you, but the example avoids the code-behind management of Visual Studio 2015.
      The point of using wpf controls is that you can easily design and modify them in Visual Studio. Using your aproach the xaml is loaded but all events and objects have to be assigend by hand and created beforehand in code.

      Basically I do still report a compiler problem of NT8 and I would like to understand better why xaml files are not compiled at all.

      Another error in the NY8 compiler is that .cs files in the Custom\bin\obj\Debug directories are automatically included in the compile. But in the list of directories or files the subfolder \obj does not even show up.

      So you can compile in VS2015, this will then generate a.g.i.cs and a.g.cs files from a.cs in the obj\Debug subfolder while VS2015 generates a correct NinjaTrader.custom.dll.

      However it seems that NT8 does not accept an externally compiled NinjaTrader.custom.dll and will always recompile internally.

      Having the obj\Debug leftover from a VS2015 compile the NT8 compile get also through, but the code is then not working as the function
      System.Windows.Application.LoadComponent(this, resourceLocater);
      will fail. Tried a few variants , but any load of the xaml fails.

      System.Uri resourceLocater = new System.Uri("/NinjaTrader.Custom;component/strategies/usercontrol2.xaml", System.UriKind.Relative);

      #line 1 "..\..\..\Strategies\UserControl2.xaml"
      System.Windows.Application.LoadComponent(this, resourceLocater);


        Hello zweistein,

        I do not know if this advice will serve your purpose, but I would program the wpf usercontrol inside Visual Studio. I would then copy and paste the usercontrol dll into the bin/Custom folder and add the dll to the references so that I can use the usercontrol in my scripts.

        The only reason I can think of for wanting to develop the usercontrol within NinjaTrader is to export it protected along with the ninjascript.


        Latest Posts


        Topics Statistics Last Post
        Started by rblunsom, Yesterday, 10:38 PM
        0 responses
        Last Post rblunsom  
        Started by Austiner87, Yesterday, 08:08 PM
        0 responses
        1 view
        Last Post Austiner87  
        Started by habibalex, Yesterday, 07:11 PM
        0 responses
        Last Post habibalex  
        Started by GMiller64, Yesterday, 05:56 PM
        1 response
        Last Post GMiller64  
        Started by rickyblah12, Yesterday, 05:01 PM
        1 response
        Last Post NinjaTrader_ShawnB