Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Programmatically change Tab ForeGround / BackGround Color

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

    Programmatically change Tab ForeGround / BackGround Color

    Hi,

    I was wondering if its possible to programatically change the forecolor or backcolor of a Tab on the onbarupdate() event such that if there is a setup in a multi-tabbed chart, the chart tabs with the setup active will become a different color... also, if its possible to dynamically change the ordering of the tab by code that would be interesting also...

    Thanks in advance.

    #2
    Possibilities

    Here's something that might be a start for you.


    Code:
    chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart;
    
    if (chartWindow == null)
    {
            Print("chartWindow == null");
            return;
    }
    
    foreach (TabItem tab in this.chartWindow.MainTabControl.Items)
    {
    
        Print(tab.Background);
    
        if ((tab.Content as ChartTab).ChartControl == this.ChartControl && tab == this.chartWindow.MainTabControl.SelectedItem)
        {
            // Do stuff with selected tab
        }
    }

    Comment


      #3
      I am able to set the property of the tabname like this

      Code:
      ChartControl.ChartTab.TabName = TabNameString; // this works

      Code:
      ChartControl.ChartTab.Background = Brushes.Red; // this does NOT work.

      Comment


        #4
        Use "Print()" to determine what the current properties are.

        Try using something like "tab.Background = System.Windows.Media.Brushes.Beige"

        I don't believe it uses an NT brush since it's using a windows control.

        Comment


          #5
          Thank you armybender...

          But unfortunately it didnt work, i get this error:

          Indicator 'BPPVer1': Error on calling 'OnBarUpdate' method on bar 120: The calling thread cannot access this object because a different thread owns it.

          I am hoping just to be able to change the color for each tab independently, so if my indicator has a condition, it can color the tab , thereby if the tab is not opened, I can be notified of the condition just by looking at the tabs.. and therefore know which one to click on and open due to an alert firing off...

          Comment


            #6
            UI Elements

            Yes, considering you are working with UI elements in a multi-threaded environment, you need to use InvokeAsync to assign the correct thread.

            This may not fall under "ChartControl", but the Dispatcher idea should get you there - it might fall under a different class, like TabControl or something. You'll have to work with that.


            Code:
            ChartControl.Dispatcher.InvokeAsync((Action)(() =>
            {
            
                // Put everything here that you already have.  This will ensure a single thread is used to execute interactions with UI elements.
            
            }));

            Comment


              #7
              Ok, I tried it and the whole chart's color changed background color (except for the tab, haha).

              I just was hoping to change the color of the tab only , that particular tab for that particular chart....

              Comment


                #8
                Well, I found "TabIndex" that you could use to move the tab from position to position.

                You can use "IsSelected" to select it.

                You might try "BorderBrush" - but I'm afraid I don't know the exact property to change that - it might take a little testing.

                Comment


                  #9
                  You might have to move back to "MainTabControl" to change properties of the actual tab

                  Comment


                    #10
                    Hello,

                    Thank you for the post.

                    I will need to confirm with development if there is already an exposed Property to set the Tab headers Brushes from NinjaScript.

                    I could not locate anything currently, so you could control the objects Style to accomplish this.

                    A sample is attached on how to create a style and apply it to an object. This does overwrite the existing Style, so if you need the original style back it would be best to save an instance of that style prior to setting a new style.

                    The same concept can be accomplished by the use of a skin as well.



                    I look forward to being of further assistance.
                    Attached Files
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I am experimenting with your xml and code, and i have two questions:

                      1) where can I get information on how to modify the xml to make different effects on the tabs?

                      2) below in the code block, how can i access the tab text for a given tab (so that I can conditionally paint the tab a color based on its content)

                      Code:
                      				foreach (TabItem tab in chartWindow.MainTabControl.Items)
                      				{
                      					if (Close.GetValueAt(bar) >= Close.GetValueAt(bar - 1))
                      					{
                      						tab.Style = greenstyle;
                      					}
                      					else if (Close.GetValueAt(bar) <= Close.GetValueAt(bar - 1))
                      					{
                      						tab.Style = redstyle;
                      					}
                      				}
                      "

                      Thank you.
                      Last edited by KhaosTrader; 08-30-2016, 06:58 PM.

                      Comment


                        #12
                        Hello,

                        it would help if I provide more information on the items I had used here.

                        The "XML" would actually be called xaml, it is a markup similar to xml but specific for dot net. WPF (windows presentation foundation) uses xaml to define UI and UI related items. In this case the xaml shown is more specifically a resource dictionary.

                        A WPF application can have a collection of these resource dictionaries that define how everything looks among other things. In this case we create a new dictionary and assign a style with a data template to a control. Without you actually making a WPF application this can be a tough concept to learn but MSDN has some pretty good examples which you can review. Additionally NinjaTrader 8 specifically uses resource dictionaries for the Skins, you can review some of the skins for more examples specific to NT8.

                        For some information on general styling in wpf and xaml, these are some resources I located that seem to contain a good portion of information.
                        Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET. Understand the types of XAML resources related to styles and themes.





                        Regarding getting the tabs header, you would need to get the Header property of the tab.

                        Code:
                        foreach (TabItem tab in chartWindow.MainTabControl.Items)
                        {
                        	Print(tab.Header);
                        }
                        "Most" of the controls used in the platform are standard WPF controls, we do have quite a few custom controls as well but knowing this will aid you in searching WPF controls.

                        For example knowing we are using a TabItem type, we could search for "TabItem Text wpf" or "TabItem Header wpf" and get the following results:


                        Use the WPF TabControl with TabItems and Grid controls. Access SelectedItem in C# code.


                        Because WPF is so broad it can be difficult to know what object has what property. While developing more advanced custom items like this, these types of searches will help explain the object in more detail.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by kevinenergy, 02-17-2023, 12:42 PM
                        116 responses
                        2,757 views
                        1 like
                        Last Post kevinenergy  
                        Started by franatas, 12-04-2023, 03:43 AM
                        7 responses
                        106 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by jpapa, Today, 07:22 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post jpapa
                        by jpapa
                         
                        Started by Jltarrau, Today, 05:57 AM
                        3 responses
                        6 views
                        0 likes
                        Last Post Jltarrau  
                        Started by f.saeidi, Today, 05:56 AM
                        2 responses
                        8 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Working...
                        X