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 development - change dynamically a textblock

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

    ADDon development - change dynamically a textblock

    have an addon (dont use XAML)
    it builds a window tab with a grid. in that grid I have an accountSelector and also a textblock.
    I would like to update the textblock with the cashvalue of the selected account at the time of the window loading and also when there is a change of the account

    I can get the cashvalue with :

    accountSelector.SelectedAccount.Get(AccountItem.Ca shValue,Currency.UsDollar).ToString()

    and I can use the AccountSelector_SelectionChanged Event Handler​ to update the text value.

    Question 1 - how exactly do I change the myTextBlock.text to the above value ?
    because the myTextBlock is not recognized in the context of the AccountSelector_SelectionChanged event handler.

    Question 2 - what event handler should I use for the initial update? it needs to be after the grid is built and populated with values.
    cant be the window_Loaded or something like that , does it ?



    #2
    Hello dadarara,

    myTextBlockReferenceVariable.Text = "My string of text to assign";

    Below is a link to the Microsoft documentation on TextBlock.


    The Loaded event would be run after the window is loaded.

    Below is a link to an example addon.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      of course I know what and how textBlock1.Text = "The text contents of this TextBlock.";
      I set the initial text when I define the textblock
      Code:
      TextBlock TextBlock1 = new TextBlock();
      TextBlock1.Text = "   xxxxx";
      TextBlock1.FontSize = 16;
      TextBlock1.VerticalAlignment = VerticalAlignment.Center;
      grid.Children.Add(TextBlock1);
      Grid.SetRow(TextBlock1, 1);
      Grid.SetColumn(TextBlock1, 1);
      ​
      its just that the textBlock1.Text is not recognized in the context of the event handler AccountSelector_SelectionChanged
      what am I doing wrong?

      so should I look for it ?
      like :

      TextBlock textblock1 = myGrid.FindName("textblock1") as TextBlock;
      if (textblock1 != null)
      {
      textblock1.Text = "New Text Value";
      }

      Comment


        #4
        Hello dadarara,

        A variable can only be used in the scope in which it is declared.

        If you declare a variable in an if statement action block, the variable only exists in the action block and cannot be used outside of the action block.
        If you declare a variable in a method, the variable only exists in the method and cannot be used outside of the method.
        If you declare a variable in the scope of a class, the variable can be used anywhere in that class in any method or if statement.

        Declare the variable in the scope of the class.

        Try adding variables with the Strategy Builder and view the code to see where the variables have been declared.

        Be sure to check that nullable type variables are not null before attempting to use them.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by janio973, Today, 07:24 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by aligator, 01-06-2022, 12:14 PM
        4 responses
        238 views
        0 likes
        Last Post john_44573  
        Started by reynoldsn, Today, 05:56 PM
        0 responses
        12 views
        0 likes
        Last Post reynoldsn  
        Started by bortz, 11-06-2023, 08:04 AM
        51 responses
        1,992 views
        0 likes
        Last Post aligator  
        Started by dmking, 11-12-2019, 12:31 PM
        4 responses
        4,156 views
        0 likes
        Last Post jasonw
        by jasonw
         
        Working...
        X