• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.

    https://blogs.msdn.microsoft.com/dev...opertychanged/

    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.

      https://blogs.msdn.microsoft.com/dev...opertychanged/

      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.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ren37, Today, 09:42 AM
        0 responses
        2 views
        0 likes
        Last Post ren37
        by ren37
         
        Started by Austiner87, Today, 08:16 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by 7robert, Today, 07:27 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by GLFX005, Today, 07:18 AM
        3 responses
        9 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by Erhard, Today, 04:24 AM
        7 responses
        27 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X