none
Reactive Extension with TreeListView RRS feed

  • Question

  • Hi,

    Are there any Examples which can help me with how I can use Reactive extensions with TreeListViewControls in MVVM - I'm new to Reactive extension and any suggestions will be of great help..

    Thanks,


    Friday, February 28, 2014 7:44 PM

Answers

  • There are some things in RX that may help you get started, one of them is the Subject class.  A Subject class allow an Observer to Subscribe very easily.  In addition the Subject class strangely support the Observable code as well.  It's a combination of both the IObserver and IObservable pattern.

    What does it look like?  (This is from memory)...

    public class MyClassContainingASubject {
    public static Subject<string> MySubject = new Subject<String>();
    //This method notifies subscribers to MySubject that something has arrived.
    public void SomeMethod(){
    foreach(var str in GetAllStrings()){
      MySubject.OnNext(str);
    }}}
    
    //But how do other classes subscribe to this?
    MyClassContainingASubject.MySubject.Subscribe(p=>{
    
      //The value of P contains the string like this
      var str = p;
      TreeNode tn = new TreeNode();
      tn.Header = str;
    });
    

    None of the code above was tested....beware!

    Check out this excellent site on RX...

    http://www.introtorx.com/

    There are two people I know of that explain RX excellently, Lee Campbell and Dave Sexton. Dave used to hang out in the RX Forum and has some code over at CodePlex. 


    JP Cowboy Coders Unite!


    Saturday, March 1, 2014 3:23 AM

All replies

  • The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. There are some good learning resources available here: http://msdn.microsoft.com/en-us/data/gg577609.aspx

    How do you want to use Rx with the TreeView control in WPF? Please clarify your issue as Rx is mainly used to represent multiple asynchronous data streams using the IObserver<T> and IObservable<T> interfaces and can be used in any type of .NET application that deals with asynchronous and event-based code.

    Friday, February 28, 2014 8:00 PM
  • Hi Magnus,

    Thanks for your response..

    What I'm trying to do is basically implement a search capability into the TreeListView using Rx (rather than use the in built filtering.. ) because I want to be able to highlight the text. Now when there are subnodes/children to a parent node,  during filtering, I would like to have the ability to expand all the parent nodes in the treeView which have the nodes that are associated to the text in the search box. This is the basic overview. 

    The idea behind using Rx for search is the ability to put in Throttle,delay etc.. into the Searchbox. This way it reduces the constant event call to the filterfunction.. 

    Suggestion will be helpful.. 

    Thanks,


    • Edited by Sdev18 Friday, February 28, 2014 9:27 PM
    Friday, February 28, 2014 9:24 PM
  • There are some things in RX that may help you get started, one of them is the Subject class.  A Subject class allow an Observer to Subscribe very easily.  In addition the Subject class strangely support the Observable code as well.  It's a combination of both the IObserver and IObservable pattern.

    What does it look like?  (This is from memory)...

    public class MyClassContainingASubject {
    public static Subject<string> MySubject = new Subject<String>();
    //This method notifies subscribers to MySubject that something has arrived.
    public void SomeMethod(){
    foreach(var str in GetAllStrings()){
      MySubject.OnNext(str);
    }}}
    
    //But how do other classes subscribe to this?
    MyClassContainingASubject.MySubject.Subscribe(p=>{
    
      //The value of P contains the string like this
      var str = p;
      TreeNode tn = new TreeNode();
      tn.Header = str;
    });
    

    None of the code above was tested....beware!

    Check out this excellent site on RX...

    http://www.introtorx.com/

    There are two people I know of that explain RX excellently, Lee Campbell and Dave Sexton. Dave used to hang out in the RX Forum and has some code over at CodePlex. 


    JP Cowboy Coders Unite!


    Saturday, March 1, 2014 3:23 AM