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

AddOn: issue with new window and GridViewColumn

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

    AddOn: issue with new window and GridViewColumn

    Hi guys,

    this is my first post, thank you in advance to anyone that is going to help me.
    I have recently started studying and trying to develop stuff with NinjaScript.

    Today I tried to build an AddOn from scratch so that I could familiarize with possibilities this feature offers.
    I've found on the forum (on the last reply of this post) a script that allows the user to create a new Menu Item that opens a window showing the opened Charts with the attached indicators and its properties.
    It was really helpful, but now I'm stuck with an issue​seems to be present in the "original" script as well.

    I try to explain it.

    My intent would be simply to have a window with a table that shows the list of the opened charts. That's it.
    I wrote a simple xaml file, which have just a single Grid.Row/Grid.Column with a GridView that has 2 Columns.
    Here it is:

    Code:
    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    
    <ListView Grid.Row="0" Grid.Column="0" x:Name="TestList" ScrollViewer.VerticalScrollBarVisibility="Visible" >
    <ListView.View>
    <GridView>
    <GridViewColumn Header="Chart" DisplayMemberBinding="{Binding Chart}" Width="200" />
    <GridViewColumn Header="Instrument" DisplayMemberBinding="{Binding Instrument}" Width="200" />
    </GridView>
    </ListView.View>
    </ListView>
    
    </Grid>
    </Page>
    The cs code seems to be working well except that for some reasons the charts data don't get shown in the window table.

    Click image for larger version  Name:	screenshot.png Views:	0 Size:	38.5 KB ID:	1176585

    As you can see in the screenshot, the table get populated with two rows but the data don't get shown.

    I upload the code of the AddOn script "Test".
    Could you please help me to figure out what's wrong?
    Thanks so much!!

    Last edited by kerplunk1899; 10-28-2021, 10:06 AM.

    #2
    Hello kerplunk1899,

    Thank you for your post.

    While this would be using unsupported code (MVVM or model-view-viewmodel and binding is advanced general C# not directly supported by NinjaTrader), it appears you are trying to add an custom class to a ListBox:

    window.Dispatcher.BeginInvoke(new Action(() =>
    {
    if (w.Caption.Contains("Chart"))
    {
    foreach (ChartControl cc in FindVisualChildren<ChartControl>(w)){
    /*Per ogni chart devo valorizzare le 2 colonne*/

    testList.Dispatcher.BeginInvoke(new Action(() => testList.Items.Add(new Charts() { Chart = cc.Instrument.FullName, Instrument = cc.Instrument.FullName })));

    }
    }
    }));

    However, I'm not seeing a template control for binding. I'd suggest taking a look at this publicly available example of binding data using a template:



    Please let us know if we may be of further assistance to you.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi!
      Thank you for your reply.
      I successfully managed to get listbox binding working.

      But I cannot get the same result with listview objects.
      I tried to follow this one with no luck: https://wpf-tutorial.com/listview-co...item-template/.

      I think something may be wrong with my code.
      I noticed that in the script I attached I wrongly defined an object as listbox instead of listview.
      But even after correcting that, it does not work.

      Can you please provide a basic example of correctly binding a listview?

      Thanks so much!

      Comment


        #4
        Hello kerplunk1899,

        Thank you for your reply.

        As mentioned previously, this would be outside the scope of what we could directly support. I do have an unsupported example of databinding, however, this does not specifically show binding a listview. The attached example demonstrates setting a parsed XAML page's DataContext and how to use a ViewModel. This also demonstrates using INotifyPropertyChanged along with updating a property. There is also a demonstration of using a DataTemplate for the DataGrid example.

        Please let us know if we may be of further assistance to you.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by PaulMohn, Today, 03:49 AM
        0 responses
        3 views
        0 likes
        Last Post PaulMohn  
        Started by inanazsocial, Today, 01:15 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by rocketman7, Today, 02:12 AM
        0 responses
        10 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        2 views
        0 likes
        Last Post dustydbayer  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        23 views
        0 likes
        Last Post trilliantrader  
        Working...
        X