add functionality to WPF observable collections item changed event without overriding it












0















I am new to WPF, and I am struggling on adding functionality on observable collections.



I have dropbox, datagrid and a list box listbox.



Data grid and list boxes are binded to corresponding observable collections.



What I want to do is, every time selection of dropbox or items in listbox(not the selection of item but the available items) change I want to call a function to populate my datagrid.



*Listbox is populated by user.



Here is my code



XAML



     <controls:SearchableDropBox DomainObject="{Binding ClassA}"                            
InputValidationManifest="{Binding ClassValidation, Mode=OneWay}"/>


<Custom:XamDataGrid DataSource="{Binding Path=ClassB.ClassList}"
GroupByAreaLocation="None" />

<controls:ListBox x:Name="listBoxInputs" ItemsSource="{Binding ClassC, Mode=oneWay}">


VIEMMODEL



 class MainViewModel : ViewModel
{
#region Attributes

private classA _classa;
private ObservableCollection<classC> _classC;
private classB;

#endregion

public MainViewModel()
{

this._classc= new ObservableCollection<classC>();
this._classB = new classB()


}

public classA ClassA
{
get { return _classA; }
set
{
if (!Equals(value, _classA))
{

_classA= value;
SelectionChanged(); //This is the function I want add on //propertychanged event
OnPropertyChanged(nameof(classA));
}

}
}

public ObservableCollection<classC> ClassC
{
get { return classC; }
set
{
this.classC= value;
OnPropertyChanged(nameof(ClassC));
}
}


ClassB



 public class classB
{
private ObservableCollection<String> _classList;

}


I want to call SelectionChanged() function when the selection of the dropbox, and when item added/deleted in list box without overriding their current notfypropertychanged events.










share|improve this question





























    0















    I am new to WPF, and I am struggling on adding functionality on observable collections.



    I have dropbox, datagrid and a list box listbox.



    Data grid and list boxes are binded to corresponding observable collections.



    What I want to do is, every time selection of dropbox or items in listbox(not the selection of item but the available items) change I want to call a function to populate my datagrid.



    *Listbox is populated by user.



    Here is my code



    XAML



         <controls:SearchableDropBox DomainObject="{Binding ClassA}"                            
    InputValidationManifest="{Binding ClassValidation, Mode=OneWay}"/>


    <Custom:XamDataGrid DataSource="{Binding Path=ClassB.ClassList}"
    GroupByAreaLocation="None" />

    <controls:ListBox x:Name="listBoxInputs" ItemsSource="{Binding ClassC, Mode=oneWay}">


    VIEMMODEL



     class MainViewModel : ViewModel
    {
    #region Attributes

    private classA _classa;
    private ObservableCollection<classC> _classC;
    private classB;

    #endregion

    public MainViewModel()
    {

    this._classc= new ObservableCollection<classC>();
    this._classB = new classB()


    }

    public classA ClassA
    {
    get { return _classA; }
    set
    {
    if (!Equals(value, _classA))
    {

    _classA= value;
    SelectionChanged(); //This is the function I want add on //propertychanged event
    OnPropertyChanged(nameof(classA));
    }

    }
    }

    public ObservableCollection<classC> ClassC
    {
    get { return classC; }
    set
    {
    this.classC= value;
    OnPropertyChanged(nameof(ClassC));
    }
    }


    ClassB



     public class classB
    {
    private ObservableCollection<String> _classList;

    }


    I want to call SelectionChanged() function when the selection of the dropbox, and when item added/deleted in list box without overriding their current notfypropertychanged events.










    share|improve this question



























      0












      0








      0


      1






      I am new to WPF, and I am struggling on adding functionality on observable collections.



      I have dropbox, datagrid and a list box listbox.



      Data grid and list boxes are binded to corresponding observable collections.



      What I want to do is, every time selection of dropbox or items in listbox(not the selection of item but the available items) change I want to call a function to populate my datagrid.



      *Listbox is populated by user.



      Here is my code



      XAML



           <controls:SearchableDropBox DomainObject="{Binding ClassA}"                            
      InputValidationManifest="{Binding ClassValidation, Mode=OneWay}"/>


      <Custom:XamDataGrid DataSource="{Binding Path=ClassB.ClassList}"
      GroupByAreaLocation="None" />

      <controls:ListBox x:Name="listBoxInputs" ItemsSource="{Binding ClassC, Mode=oneWay}">


      VIEMMODEL



       class MainViewModel : ViewModel
      {
      #region Attributes

      private classA _classa;
      private ObservableCollection<classC> _classC;
      private classB;

      #endregion

      public MainViewModel()
      {

      this._classc= new ObservableCollection<classC>();
      this._classB = new classB()


      }

      public classA ClassA
      {
      get { return _classA; }
      set
      {
      if (!Equals(value, _classA))
      {

      _classA= value;
      SelectionChanged(); //This is the function I want add on //propertychanged event
      OnPropertyChanged(nameof(classA));
      }

      }
      }

      public ObservableCollection<classC> ClassC
      {
      get { return classC; }
      set
      {
      this.classC= value;
      OnPropertyChanged(nameof(ClassC));
      }
      }


      ClassB



       public class classB
      {
      private ObservableCollection<String> _classList;

      }


      I want to call SelectionChanged() function when the selection of the dropbox, and when item added/deleted in list box without overriding their current notfypropertychanged events.










      share|improve this question
















      I am new to WPF, and I am struggling on adding functionality on observable collections.



      I have dropbox, datagrid and a list box listbox.



      Data grid and list boxes are binded to corresponding observable collections.



      What I want to do is, every time selection of dropbox or items in listbox(not the selection of item but the available items) change I want to call a function to populate my datagrid.



      *Listbox is populated by user.



      Here is my code



      XAML



           <controls:SearchableDropBox DomainObject="{Binding ClassA}"                            
      InputValidationManifest="{Binding ClassValidation, Mode=OneWay}"/>


      <Custom:XamDataGrid DataSource="{Binding Path=ClassB.ClassList}"
      GroupByAreaLocation="None" />

      <controls:ListBox x:Name="listBoxInputs" ItemsSource="{Binding ClassC, Mode=oneWay}">


      VIEMMODEL



       class MainViewModel : ViewModel
      {
      #region Attributes

      private classA _classa;
      private ObservableCollection<classC> _classC;
      private classB;

      #endregion

      public MainViewModel()
      {

      this._classc= new ObservableCollection<classC>();
      this._classB = new classB()


      }

      public classA ClassA
      {
      get { return _classA; }
      set
      {
      if (!Equals(value, _classA))
      {

      _classA= value;
      SelectionChanged(); //This is the function I want add on //propertychanged event
      OnPropertyChanged(nameof(classA));
      }

      }
      }

      public ObservableCollection<classC> ClassC
      {
      get { return classC; }
      set
      {
      this.classC= value;
      OnPropertyChanged(nameof(ClassC));
      }
      }


      ClassB



       public class classB
      {
      private ObservableCollection<String> _classList;

      }


      I want to call SelectionChanged() function when the selection of the dropbox, and when item added/deleted in list box without overriding their current notfypropertychanged events.







      wpf binding observablecollection inotifypropertychanged xamdatagrid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 15:05









      Satish Pai

      7841510




      7841510










      asked Nov 24 '18 at 9:00









      Guray GolcukGuray Golcuk

      336




      336
























          1 Answer
          1






          active

          oldest

          votes


















          1














          For add/Remove in _classC collection, you subscribe to CollectionChanged event.



               public MainViewModel()
          {
          this._classc= new ObservableCollection<classC>();
          this._classB = new classB()
          _classC.CollectionChanged += _classC_CollectionChanged;
          }

          private void _classC_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
          //Populate ClassB.ClassList / Datagrid Function Call
          }





          share|improve this answer
























          • @GurayGolcuk was solution helpful ?

            – Satish Pai
            Nov 25 '18 at 16:35











          • yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

            – Guray Golcuk
            Nov 26 '18 at 8:18













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456673%2fadd-functionality-to-wpf-observable-collections-item-changed-event-without-overr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          For add/Remove in _classC collection, you subscribe to CollectionChanged event.



               public MainViewModel()
          {
          this._classc= new ObservableCollection<classC>();
          this._classB = new classB()
          _classC.CollectionChanged += _classC_CollectionChanged;
          }

          private void _classC_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
          //Populate ClassB.ClassList / Datagrid Function Call
          }





          share|improve this answer
























          • @GurayGolcuk was solution helpful ?

            – Satish Pai
            Nov 25 '18 at 16:35











          • yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

            – Guray Golcuk
            Nov 26 '18 at 8:18


















          1














          For add/Remove in _classC collection, you subscribe to CollectionChanged event.



               public MainViewModel()
          {
          this._classc= new ObservableCollection<classC>();
          this._classB = new classB()
          _classC.CollectionChanged += _classC_CollectionChanged;
          }

          private void _classC_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
          //Populate ClassB.ClassList / Datagrid Function Call
          }





          share|improve this answer
























          • @GurayGolcuk was solution helpful ?

            – Satish Pai
            Nov 25 '18 at 16:35











          • yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

            – Guray Golcuk
            Nov 26 '18 at 8:18
















          1












          1








          1







          For add/Remove in _classC collection, you subscribe to CollectionChanged event.



               public MainViewModel()
          {
          this._classc= new ObservableCollection<classC>();
          this._classB = new classB()
          _classC.CollectionChanged += _classC_CollectionChanged;
          }

          private void _classC_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
          //Populate ClassB.ClassList / Datagrid Function Call
          }





          share|improve this answer













          For add/Remove in _classC collection, you subscribe to CollectionChanged event.



               public MainViewModel()
          {
          this._classc= new ObservableCollection<classC>();
          this._classB = new classB()
          _classC.CollectionChanged += _classC_CollectionChanged;
          }

          private void _classC_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
          //Populate ClassB.ClassList / Datagrid Function Call
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 11:53









          Satish PaiSatish Pai

          7841510




          7841510













          • @GurayGolcuk was solution helpful ?

            – Satish Pai
            Nov 25 '18 at 16:35











          • yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

            – Guray Golcuk
            Nov 26 '18 at 8:18





















          • @GurayGolcuk was solution helpful ?

            – Satish Pai
            Nov 25 '18 at 16:35











          • yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

            – Guray Golcuk
            Nov 26 '18 at 8:18



















          @GurayGolcuk was solution helpful ?

          – Satish Pai
          Nov 25 '18 at 16:35





          @GurayGolcuk was solution helpful ?

          – Satish Pai
          Nov 25 '18 at 16:35













          yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

          – Guray Golcuk
          Nov 26 '18 at 8:18







          yeah yeah, sorry for the late reply, because of some bug, This approach only calls the function without updating the view, but I fix it now. thank you

          – Guray Golcuk
          Nov 26 '18 at 8:18






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456673%2fadd-functionality-to-wpf-observable-collections-item-changed-event-without-overr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'