Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change Custom Button's Color after clicking

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

    Change Custom Button's Color after clicking

    Hello,

    I added a custom button in chart trader, and I want to change the color when I click on the button.

    I have a Bool i called it armLong to chnage from true to false dependent on clicks,

    this is where i am creatign the button :

    HTML Code:
    protected void CreateWPFControls()
            {
                chartWindow                = Window.GetWindow(ChartControl.Parent) as Gui.Chart.Chart;
    
                if (chartWindow == null)
                    return;
    
                chartTraderGrid            = (chartWindow.FindFirst("ChartWindowChartTraderControl") as Gui.Chart.ChartTrader).Content as System.Windows.Controls.Grid;
    
                chartTraderButtonsGrid    = chartTraderGrid.Children[0] as System.Windows.Controls.Grid;
    
                lowerButtonsGrid = new System.Windows.Controls.Grid();
                lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
                lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
    
                addedRow1    = new System.Windows.Controls.RowDefinition() { Height = new GridLength(60) };
                addedRow2    = new System.Windows.Controls.RowDefinition() { Height = new GridLength(200) };
                    longButton = new System.Windows.Controls.Button()
                    {        
    
                        Content            = string.Format("Arm Long"),
                        Height            = 25,
                        Margin            = new Thickness(5,0,5,0),
                        Padding            = new Thickness(0,0,0,0)
                    };    
    
                    // change colors of the buttons
                    if(armLong == true){
                        longButton.Background    = Brushes.Gray;
                    }else if (armLong == false) {
                        longButton.Background    = Brushes.Lime;
                    }
    
                        longButton.Click +=  ARMLong;    
                        lowerButtonsGrid.Children.Add(longButton);    
    
                if (TabSelected())
                    InsertWPFControls();
    
                chartWindow.MainTabControl.SelectionChanged += TabChangedHandler;
            }​
    and this is where i change the armLong Bool:

    HTML Code:
    protected void ARMLong(object sender, RoutedEventArgs e)
            {
                Print("------------------------------");
                Print("Before Change : " + armLong);
                armLong = !armLong;
                Print("after Change : " + armLong);
                ForceRefresh();
            }​

    but It didnt update when i click on the button, the color stays the same :/

    How can I fix this please

    thank you in advance
    Attached Files

    #2
    Hello pechtri,

    Thanks for your post.

    Please review the sample script on the forum thread linked below that demonstrates how to modify the button background color when the button is clicked. You could compare this sample to your script to see where differences might be.
    I found the code posted by NinaTrader_ZacharyG and it's exactly what I needed! I couldn't have accomplished this on my own and I'm extremely grateful for the generosity. One small modification I'd like to make is to change the button color when it's clicked. Does anyone have a snippet of code showing how this is accomplished


    If the script is not behaving as expected then further debugging prints should be added to the script to understand exactly how the logic is behaving. Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you very much it worked

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      131 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X