Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Two buttons two pages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Two buttons two pages

    Hello to the forum!

    I am developing an add-on with WPF.
    For this I use as a template "AddonShellNoTabs".

    I would like to call a page 1 and a page 2 via two buttons.

    (Example with Visual Studio)
    Button 1 clicked


    Button 2 clicked


    For this I need a frame.

    A frame in the XAML file is not recognized by NT8.

    Using Frame as a method also does not work.


    How can I set up a frame with two buttons?

    Thanks for the support!


    #2
    Hello user10,

    Can you provide the syntax for what you have tried and any errors you had seen? Also what content are you trying to display in the pages?

    Generally WPF development is not something we can provide direct assistance with, this is a subject which you can find many resources for online as this is not a NinjaTrader specific concept. Depending on the problem, I may be able to assist otherwise I can try to provide guidance on how to locate resources on that topic.

    If you have created something in Visual Studio, that is most likely going to be using a "Window" instead of a "Page" which the addon samples use. This may be one item you need to change in your visual studio project so you can work with the correct syntax.

    Frame is part of the WPF controls, you can either use visual studio to construct what you want or manually type the xaml syntax to create a frame or buttons.

    if you are trying to create something similar to what NinjaTrader loads you would need to make the xaml Page in the same way that the example shows. This is generally a Page which has other controls in it:

    Code:
    <Page    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrader.Gui"
            xmlns:system="clr-namespace:System;assembly=mscorlib">
    
    
    controls here
    
    </Page>
    I would suggest also looking at the xaml file that comes with the addon sample basic for some examples of building a xaml control which is then loaded as an addon: https://ninjatrader.com/support/help...t_overview.htm



    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      To list the mistakes here would be too long ...
      I spent hours trying to solve the problem.

      The current work status is that a window opens and I can load my pages and fill them with content.

      My problem is that I want to address several pages with different content.
      To switch between the pages, I have to use a frame to my knowledge. It's easy with VS.
      Ilford Grammar School, C#, Pages, Frames, Pages and Navigation


      When I insert a frame under "controls here", I get an empty window.
      I tried to load a frame in NT8 and get the same result.

      Do I understand you correctly that I can not use frame in NT8?
      (Then there would only be the possibility to use buttons on every page and refer back to the respective page?)

      Many thanks for the support!

      Comment


        #4
        Hello user10,

        Code:
        To list the mistakes here would be too long ...
        I spent hours trying to solve the problem.
        Without knowing the problem I am unsure how I could continue to assist. The description you provided is not enough information to know what the problem may be.

        If you have spent some time creating something but you are stuck somewhere, that would be the part of the details I need to know or what you are stuck on. Otherwise really all I could suggest would be what I did in the last post. You can review the addon sample in the help guide for guidance on how the platform loads xaml. NinjaTrader does not work like Visual Studio using xaml. An addon loads and parses a xaml file as text which is different than how a basic C# application works.

        It looks like in the video you provided you have multiple xaml files, so for that you would need to essentially replicate how the platform loads the xaml for each file to load each as an object. Once you have objects of each page, you could do other logic to apply the pages to the frame in the code, this would all need to be done in code due to how the xaml is loaded. This is not something I can provide a sample of but you can experiment with this and review the existing addon sample for guidance on parsing the xaml file.

        If you are trying to create buttons to change pages, would the existing Tab system of the addon not apply here? That is the general suggestion if you wanted to make an addon with more than one content, you can create as many different tabs as needed and they do not need to be the same content. The addon sample which is in the help guide contains a class which inherits from INTTabFactory, this can be used to delegate new tab creation, also the tc.AddNTTabPage() method can be used to create a set of default tabs which open.

        Code:
        When I insert a frame under "controls here", I get an empty window.
        I tried to load a frame in NT8 and get the same result.
        Did you use valid syntax? Xaml errors are not reported in NinjaTrader, if you used invalid syntax the page will fail to parse leaving a blank content.

        Do I understand you correctly that I can not use frame in NT8?
        (Then there would only be the possibility to use buttons on every page and refer back to the respective page?)
        This was not mentioned in my post, you can use the Frame as part of WPF/Xaml. I would not likely suggest using a Frame if the purpose is to switch content as the Tab system is for that specific purpose.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          you're right; without code it does not work.

          As MainPage I use the following XAML code.
          #
          <Pagexmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrad er.Gui"
          xmlns:editors="http://infragistics.com/Editors">
          <!--<Frame x:Name= "MyFrame" Margin="0,30,0,0"> </Frame> ??-->
          <Grid>
          <Grid.ColumnDefinitions>
          <ColumnDefinitionWidth="100"/>
          reduced
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
          <RowDefinitionHeight="0"/>
          reduced
          </
          Grid.RowDefinitions>
          <!-- Buttons Change Page-->
          <Buttonx:Name="Button1"Grid.Column="0"Grid.Row="1"Content="Page1"HorizontalAlignment="Left"VerticalAlignment="Top"VerticalContentAlignment="Center"HorizontalContentAlignment="Center"/>
          <Buttonx:Name="Button2"Grid.Column="1"Grid.Row="1"Content="Page2"HorizontalAlignment="Left"VerticalAlignment="Top"VerticalContentAlignment="Center"HorizontalContentAlignment="Center"/>


          <!--> <Frame x:Name= "MyFrame" Margin="0,100,0,0"> </Frame> ??
          <Frame Source="C:\Users\User\Documents\NinjaTrader 8\bin\Custom\AddOns\PageFrame.xaml"> </Frame> ??
          <Frame x:Name= "MyFrame" Margin="0,100,0,0" Source="C:\Users\User\Documents\NinjaTrader 8\bin\Custom\AddOns\PageFrame.xaml"> </Frame> ??
          -->

          <TextBlockx:Name= "Textblock1"Grid.Column="0"Grid.Row="3"HorizontalAlignment="Left"VerticalAlignment="Top"Height="16"Width="150"/>
          </Grid> </Page>

          #

          For the page to load I use this code

          # <Pagexmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          reduced

          <Grid>
          <TextBlockText="Page1"HorizontalAlignment="Left"VerticalAlignment="Top"FontSize="20"/>
          </Grid>
          </Page>

          #

          Within NT8:

          PHP Code:
              public DashBoardWindow()
                  {
                      
          Caption    "DashBoard";
                      
          Width    300;
                      
          Height    250;
                      
          Content    LoadXaml();
           
          //         Content = LoadFrame(); //??
          //            Frame = LoadFrame(); //??

                      // reduced //
                  
          }

                  private 
          void Button1_Click(object senderRoutedEventArgs e)
                  {
                      
          NinjaTrader.Code.Output.Process("Button1 clicked"PrintTo.OutputTab1);
                      
          Content LoadXamlPage1();
                      
          Content LoadFrame();
          //          Frame = LoadFrame();
                  
          }

                  private 
          void Button2_Click(object senderRoutedEventArgs e)
                  {
                      
          NinjaTrader.Code.Output.Process("Button2 clicked"PrintTo.OutputTab1);
                      
          Content LoadXamlPage2();
                  }

                  private 
          DependencyObject LoadFrame() //??
                  
          {
                      try
                      {
                          
          Frame frame = new Frame();
                          
          FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, @"bin\Custom\AddOns\PageFrame.xaml"), FileMode.Open);
                          
          frame = (Frame)XamlReader.Load(fs);
          //              DependencyObject frameContent = frame.Content as DependencyObject;
                          
          DependencyObject frameContent frame.Content as Frame;

                           
          // Test
          //                Ellipse myEllipse1 = new Ellipse();
           //               myEllipse1 = LogicalTreeHelper.FindLogicalNode(frame, "Cond1") as Ellipse;


                          
          return frameContent;

                        
          //reduced //
                  
          }

                  private 
          DependencyObject LoadXaml()
                  {
                      try
                      {
                          
          Page page;
                          
          FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, @"bin\Custom\AddOns\PageMain.xaml"), FileMode.Open);
                          
          page = (Page)XamlReader.Load(fs);

                          
          // Frame
          //                Frame frame = new Frame();
          //                frame.Height = 100;
          //                frame = LogicalTreeHelper.FindLogicalNode(page, "MyFrame") as Frame;


          //                // Button
          //                button1 = LogicalTreeHelper.FindLogicalNode(page, "Button1") as Button;
          //                if (button1 != null)
          //                    button1.Click += Button1_Click;

          //                button2 = LogicalTreeHelper.FindLogicalNode(page, "Button2") as Button;
          //                if (button2 != null)
          //                    button2.Click += Button2_Click;

          //                // TestBlock
          //                textString1 = LogicalTreeHelper.FindLogicalNode(page, "Textblock1") as TextBlock;
          //                textString1.Text = ( "Load Page 1");

                          
          DependencyObject pageContent page.Content as DependencyObject;

                          return 
          pageContent

          When I insert the frame, I get an empty window.
          I've shortened the code in some places; basically the code is running.
          My question is: how can I insert a frame in MainPage?

          Comment


            #6
            Hello user10,

            Thank you for providing that.

            Going back to the prior post this comment is relevant to what you have provided:

            It looks like in the video you provided you have multiple xaml files, so for that you would need to essentially replicate how the platform loads the xaml for each file to load each as an object. Once you have objects of each page, you could do other logic to apply the pages to the frame in the code, this would all need to be done in code due to how the xaml is loaded. This is not something I can provide a sample of but you can experiment with this and review the existing addon sample for guidance on parsing the xaml file.
            Code:
            <Frame Source="C:\Users\User\Documents\NinjaTrader 8\bin\Custom\AddOns\PageFrame.xaml"> </Frame> ??
            <Frame x:Name= "MyFrame" Margin="0,100,0,0" Source="C:\Users\User\Documents\NinjaTrader 8\bin\Custom\AddOns\PageFrame.xaml">
            In this syntax you are using a direct path which this xaml will not be processed. The empty window will be when the xaml was unable to be processed or has an error because the Content was not applied.

            You would need to use C# code instead of xaml to apply the frame contents to the frame.

            It looks like you have a LoadFrame method, this is what would be needed or to load and parse the xaml into an object. After loading the frames contents, you could set it as the contents for the target frame. For this part you can search online for C# ways to apply frame contents programatically instead of by using Xaml. This is not something which is specific to NinjaScript so this is not going to be something we document or have samples for. Very likely you will need to set the frames Source property as that is what you were using in the xaml: Source=.

            When loading Xaml in NinjaScript, because this is manually loaded you loose most of the features xaml has in regard to defining sources, binding, using event handlers or the xaml.cs code behind file. You will need to search online for alternative code only ways to execute your xaml ideas such as applying content to a frame programatically. I did a quick google search and found the following stackoverflow answer of changing a page programatically with a frame: https://stackoverflow.com/a/138315


            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samish18, Yesterday, 08:31 AM
            4 responses
            14 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by funk10101, Yesterday, 09:43 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            5 responses
            551 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rtwave, 04-12-2024, 09:30 AM
            5 responses
            37 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by funk10101, Today, 12:02 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X