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

ChartTrader add-on with xaml template.

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

    ChartTrader add-on with xaml template.

    Hello,
    I working on add-on which integrates with ChartTrader.
    I have two questions:
    1. Is there is a way to identify if another add-on already hosted in char trader and how to correctly place my add-on in Grid and to not broke another integration.
    2. I faced an issue while working with ListView item template which is content for an expander. I have simple code:
    Code:
    private ListView ListView;
    
    protected override void OnWindowCreated(Window window)
    {
      // chart trader routine.
      // Create the Grid
                var userControl = new UserControl();
                Grid.SetRow(userControl, 8);
    
                userControl.Content = LoadPositionPlacingXML();
    
                _mainGrid.Children.Add(userControl);​
    }
    
    private DependencyObject LoadPositionPlacingXML()
    {
      Expander = LogicalTreeHelper.FindLogicalNode(xaml, "Expander") as Expander;
      CreateListView();
      // _listViewSource is ObservableCollection
      _listViewSource.Add(new NewClass() { Element = "100" });
      _listViewSource.Add(new NewClass() { Element = "100" });
      _listViewSource.Add(new NewClass() { Element = "100" });
      _listViewSource.Add(new NewClass() { Element = "100" });
      _listViewSource.Add(new NewClass() { Element = "100" });
      ListView.ItemsSource = _listViewSource;
      Expander.Content = ListView;​
    }
    
    private void CreateListView()
            {
                // Create the ListView
                ListView = new System.Windows.Controls.ListView();
    
                // Create the item template
                DataTemplate itemTemplate = new DataTemplate();
    
                // Create the Grid
                FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid));
    
                FrameworkElementFactory col1 = new FrameworkElementFactory(typeof(ColumnDefinition));
                FrameworkElementFactory col2 = new FrameworkElementFactory(typeof(ColumnDefinition));
                FrameworkElementFactory col3 = new FrameworkElementFactory(typeof(ColumnDefinition));
    
                FrameworkElementFactory row = new FrameworkElementFactory(typeof(RowDefinition));
                FrameworkElementFactory row1 = new FrameworkElementFactory(typeof(RowDefinition));
    
                col1.SetValue(ColumnDefinition.WidthProperty, new GridLength(4, GridUnitType.Star));
                col2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));
                col3.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));
    
                row.SetValue(RowDefinition.HeightProperty, new GridLength(1, GridUnitType.Auto));
                row1.SetValue(RowDefinition.HeightProperty, new GridLength(1, GridUnitType.Star));
    
                gridFactory.AppendChild(col1);
                gridFactory.AppendChild(col2);
                gridFactory.AppendChild(col3);
    
                // Create the TextBlock
                FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
                textBlockFactory.SetValue(TextBlock.TextProperty, "Some text %");
                textBlockFactory.SetValue(Grid.RowProperty, 0);
                textBlockFactory.SetValue(Grid.ColumnSpanProperty, 3);
                textBlockFactory.SetValue(TextBlock.FontSizeProperty, 8.0);
                textBlockFactory.SetValue(TextBlock.ForegroundProperty, Brushes.LightGray);
    
                // Create the TextBox
                FrameworkElementFactory textBoxFactory = new FrameworkElementFactory(typeof(NumericTextBox));
                textBoxFactory.SetValue(Grid.RowProperty, 1);
                textBoxFactory.SetValue(Grid.ColumnProperty, 0);
    
                Binding positionBinding = new Binding("Element");
                textBoxFactory.SetBinding(NumericTextBox.TextProperty, positionBinding);
    
                // Create the Button "-"
                FrameworkElementFactory minusButtonFactory = new FrameworkElementFactory(typeof(System.Windows.Controls.Button));
                minusButtonFactory.SetValue(Grid.RowProperty, 1);
                minusButtonFactory.SetValue(Grid.ColumnProperty, 1);
                minusButtonFactory.SetValue(System.Windows.Controls.Button.ContentProperty, "-");
    
                // Create the Button "+"
                FrameworkElementFactory plusButtonFactory = new FrameworkElementFactory(typeof(System.Windows.Controls.Button));
                plusButtonFactory.SetValue(Grid.RowProperty, 1);
                plusButtonFactory.SetValue(Grid.ColumnProperty, 2);
                plusButtonFactory.SetValue(System.Windows.Controls.Button.ContentProperty, "+");
    
                // Add the child elements to the Grid
                gridFactory.AppendChild(textBlockFactory);
                gridFactory.AppendChild(textBoxFactory);
                gridFactory.AppendChild(minusButtonFactory);
                gridFactory.AppendChild(plusButtonFactory);
    
                // Set the Grid as the visual tree of the DataTemplate
                itemTemplate.VisualTree = gridFactory;
    
                // Assign the item template to the ListView
                ListView.ItemTemplate = itemTemplate;
            }
    
    public class NewClass
    {
       public string Element {get;set;}
    }​
    Same code result in default WPF solution :
    Click image for larger version  Name:	1.png Views:	0 Size:	7.0 KB ID:	1256170
    Chart Trader result:
    Click image for larger version  Name:	2.png Views:	0 Size:	1.3 KB ID:	1256171

    Is there is some specifics that I don't know? How can I specify list view item template and correctly bind properties for list item?

    Thanks
    Last edited by yyesyyesyyes; 06-14-2023, 02:53 PM.

    #2
    Hello yyesyyesyyes,

    There wouldn't be any NinjaScript ways to know that as you are just working with the WPF controls at that point. If you have something else that is modifying the same control they may conflict.

    Regarding the list that would be outside of what our support could assist with. You may need to research that in external WPF related guides to see if you can find a solution. It is also possible that when using WPF controls in NinjaTrader they won't work or appear correctly because the platform has built in styles that are being used. If any users have used a listview with a template they will be able to reply here with their experience.


    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by gyilaoliver, Today, 03:31 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by seanthenoob, 06-19-2020, 10:16 AM
    8 responses
    672 views
    0 likes
    Last Post Brockjava  
    Started by mtamaku, Yesterday, 11:08 AM
    10 responses
    24 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PaulMohn, 01-04-2024, 10:08 AM
    6 responses
    122 views
    0 likes
    Last Post SnailHorn  
    Started by Rafaelseki, Today, 03:14 AM
    2 responses
    10 views
    0 likes
    Last Post Rafaelseki  
    Working...
    X