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

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
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        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 Skifree, Today, 03:41 AM
            1 response
            2 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            23 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            23 views
            0 likes
            Last Post Pattontje  
            Working...
            X