In my application i am using Reactive extensions for making web request . What my issue is, i am making two requests. In the first request i will get a url from the sever and by using that url i am sending another request for fetching image and description. In my first request apart from url i will get the title and date related information. So what i am doing is i will parse the data in my model class and from there i will call the other request. Here when i receive response i will add that in to my class object that can hold the result. And when the complete(onnext,error,complete) portion of my first request reaches i will get the both result in my property. But the issue is that the corresponding change ,ie the result of second web request is not reflecting on my UI. Please anyone help me to avoid this issue.

有帮助吗?

解决方案

Here's how I would structure your code - it's not a complete solution as you'll need to fill in the blanks a bit - but it should make it easier.

I started with the assumption that you would have classes like this:

public class X
{
    public Uri Uri { get; set; }
    public string Title { get; set; }
    public DateTime Date { get; set; }
}

public class Y
{
    public System.Drawing.Image Image { get; set; }
    public string Description { get; set; }
}

public class Z
{
    public Uri Uri { get; set; }
    public string Title { get; set; }
    public DateTime Date { get; set; }
    public System.Drawing.Image Image { get; set; }
    public string Description { get; set; }
}

Now I created these two functions:

Func<IObservable<X>> getX =
    () =>
        {
            /* you must write this code */
        };

Func<X, IObservable<Y>> getYFromX =
    x =>
        {
            /* you must write this code */
        };

They represent the two parts of your code.

Here's how to join them together:

IObservable<Z> getZ =
    from x in getX()
    from y in getYFromX(x)
    select new Z()
    {
        Uri = x.Uri,
        Title = x.Title,
        Date = x.Date,
        Image = y.Image,
        Description = y.Description,
    };

The Rx magic using SelectMany here joins your two sub-parts together. Hopefully it'll be easier for you to define the getX & getYFromX functions.

其他提示

Are you a) jumping back to the UI thread using ObserveOnDispatcher()? and b) raising INotifyPropertyChanged.PropertyChanged events on the properties of the class you are setting as the DataContext?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top