Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ListView does not show data

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

    ListView does not show data

    This code works fine with WPF; there is no problem. It shows the date correctly. The same code does not work with Nightrider.
    Kindly help.

    public class WinUiIndicator : Indicator
    {
    private System.Windows.Controls.Canvas canvasForListView;
    private System.Windows.Controls.ListView listViewData = null;

    public class Person
    {
    public string Name { get; set; }
    public int Age { get; set; }
    }

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"ListView for Data";
    Name = "WinUiIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.Historical)
    {
    // Because we're dealing with UI elements, we need to use the Dispatcher which created the object
    // otherwise we will run into threading errors...
    // e.g, "Error on calling 'OnStateChange' method: You are accessing an object which resides on another thread."
    // Furthermore, we will do this operation Asynchronously to avoid conflicts with internal NT operations
    ChartControl.Dispatcher.InvokeAsync((() =>
    {
    // Grid already exists
    if (UserControlCollection.Contains(canvasForListView) )
    return;

    // Add a control grid which will host our custom buttons
    canvasForListView = new System.Windows.Controls.Canvas
    {
    Name = "CanvasForListView",
    // Align the control to the top right corner of the chart
    HorizontalAlignment = HorizontalAlignment.Center,
    VerticalAlignment = VerticalAlignment.Top,
    Background = Brushes.Red,
    Height = 200,
    Width = 1000,
    };

    listViewData = new ListView();
    GridView gridView = new GridView();

    GridViewColumn nameColumn = new GridViewColumn { Header = "Name", DisplayMemberBinding = new Binding("Name") };
    GridViewColumn ageColumn = new GridViewColumn { Header = "Age", DisplayMemberBinding = new Binding("Age") };

    gridView.Columns.Add(nameColumn);
    gridView.Columns.Add(ageColumn);

    listViewData.View = gridView;


    ObservableCollection<Person> people = new ObservableCollection<Person>
    {
    new Person { Name = "John Doe", Age = 30 },
    new Person { Name = "Jane Smith", Age = 25 }
    };

    listViewData.ItemsSource = people;

    Canvas.SetLeft(listViewData, 100);
    canvasForListView.Children.Add(listViewData);
    // Finally, add the completed grid to the custom NinjaTrader UserControlCollection
    UserControlCollection.Add(canvasForListView);

    }));
    }
    }

    private void SendMessage(string functionName)
    {
    ClearOutputWindow();
    DateTime dt = DateTime.Now;
    Print($"I am inside {functionName} and Time is {dt.ToLongTimeString()}");
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.


    }
    }​

    #2
    Hello AghaKhan,

    Thank you for your post.

    What exactly isn't working in the code? I'm not familiar with Nightrider, what exactly are you trying to do?

    Comment


      #3
      My objective was to show some information—for example, the distance between 2 moving averages. After spending more than a day, I realized it was a bug in the Ninja Trader implementation. The sample code is just to show the bug and has nothing to do with moving averages. I have a header (Name, Age, ...) that does not show the content. Name =John Doe, Age = 30. The bug is that it only shows the header and nothing else (No data). There is no binding. listViewData.ItemsSource = people; does not work. Thanks for your reply.

      Comment


        #4
        Hello,

        This may be due to the sizing of the control. It would be difficult to say what is different between WPF and NinjaTrader's UserControlCollection.



        We suggest starting by making a grid that has a colored background (in order to see the grid's outline) and then add the control. Make sure the control is stretched to the size of the grid and has a width/height.

        Comment


          #5
          I tried all. It is confirmed it is a bug inside the NinjaTrader script.

          Comment


            #6
            Hello AghaKhan,

            Thank you for your response.

            Please note that using a ListView is an advanced C# concept and is not fully supported by the Scripting Support team.

            There can be limitations using unsupported code and advanced C# concepts in a NinjaScript, so your mileage may very as to whether or not certain code will work in NinjaScript . As of now, we do not have any examples that can be used to create a ListView within an indicator.

            However, ListViews have been successfully implemented in AddOn script. Please note the following examples are unsupported by NinjaTrader Support.




            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X