Announcement

Collapse
No announcement yet.

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 Chuso, 01-14-2025, 03:41 AM
    4 responses
    22 views
    0 likes
    Last Post Chuso
    by Chuso
     
    Started by steinberg123, 01-09-2025, 05:48 AM
    3 responses
    38 views
    0 likes
    Last Post steinberg123  
    Started by Mindset, 01-14-2025, 05:33 AM
    2 responses
    12 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by steinberg123, Today, 02:43 AM
    0 responses
    6 views
    0 likes
    Last Post steinberg123  
    Started by r68cervera, Today, 02:22 AM
    0 responses
    7 views
    0 likes
    Last Post r68cervera  
    Working...
    X