Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        557 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X