Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Implementing INotifyPropertyChanged for WPF in Ninjascript

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

    Implementing INotifyPropertyChanged for WPF in Ninjascript

    I have a strategy that adds comboxes to the ChartWindow MainMenu. Changing the selections in the comboxes changes the indicator's behavior. This works. However, I want to be able to programatically change the SelectedItem of the combobox. That is if I change the value of the underlying property the control is bound to, the combobox will update to refelct the change. To do this I must implement the INotifyPropertyChanged interface. When I implement this the PropertyChanged handler is always null because the DataContext is not set. How do I properly set the datacontext so that I can properly implement traditional 2 way wpf bindings?

    #2
    Hello TheWhiteDragon,

    Thanks for your post.

    WPF modifications are not specifically NinjaScript, so external resources on WPF could be useful for further direction.

    I have included a link to one such publicly available resource that can demonstrate binding a ComboBox with INotifyPropertyChanged.



    Another approach could be to add event handlers to each ComboBox's SelectionChanged event. I have attached an example that demonstrates adding event handlers to detect changes to a ComboBox and to modify another Combo Box.

    Please let us know if we can be of further assistance.
    Attached Files

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello TheWhiteDragon,

      Thanks for your post.

      WPF modifications are not specifically NinjaScript, so external resources on WPF could be useful for further direction.

      I have included a link to one such publicly available resource that can demonstrate binding a ComboBox with INotifyPropertyChanged.



      Another approach could be to add event handlers to each ComboBox's SelectionChanged event. I have attached an example that demonstrates adding event handlers to detect changes to a ComboBox and to modify another Combo Box.

      Please let us know if we can be of further assistance.
      So to use the link that you posted as an example the part that I'm having trouble with is this:

      Code:
      public ComboBox() 
              { 
                  InitializeComponent(); 
                  DataContext = this;
      So you can't set the DataContext to this because indicator is not a type with a DataContext.

      Comment


        #4
        Hello TheWhiteDragon,

        Correct, DataContext would not be available directly from an indicator/strategy as they are not inherited with that object. DataContext would be available in the Control itself and you can create your own view model to bind with. This is similar to the guide linked previously, but the guide below would be more accurate as it does not involve InitializeComponent() or DataContext directly.

        How to: Create a Binding in Code: - https://docs.microsoft.com/en-us/dot...inding-in-code

        I have also attached a sample that can demonstrate usage in a NinjaScript strategy. This should work in the context of an indicator as well.

        Please note that the code used in this example is not documented/supported NinjaScript.

        I look forward to being of further assistance.
        Attached Files
        Last edited by NinjaTrader_Jim; 04-05-2021, 08:50 AM.

        Comment


          #5
          Hello NinjaTrader_Jim,

          Special request.
          I find I learn a lot from your shared samples, thanks.
          But the problem is they are scattered across many threads and not directly all accessible in one place.
          I could check all you posts for shared content.
          Easier way would be to ask if you have them ready in a nice folder archive you would be keen on sharing.
          Still better would be to have each NT technician do provide the same archives pinned to their profile pages.
          So we could go over these first when searching that would save potentially a good amount of time.

          In the mean time, do you have ready an archive of all the samples and scripts you shared on the forum I could download now?
          Thanks again!​

          Comment


            #6
            Hello PaulMohn,

            Unfortunately, there is not an archive of all samples posted on the forums.

            You can view all posts from user by visiting the profile page for that user.

            Currently, we are working on gathering our examples for our support portal.
            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
            668 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            377 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            110 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X