WP7 Developpement:如何使程序等到EventHandler结束?

时间:2012-05-03 22:16:50

标签: windows-phone-7 windows-phone-7.1

当我的视图需要LogoStation的值时,它会返回null,因为我的程序尚未执行LoadStation_Completed。

我希望我的程序在继续之前等待执行LoadStation_Completed。

THX

public class Infos
{
    #region propriétés

    private DataServiceCollection<SyndicObject> _infosStation;
    public DataServiceCollection<SyndicObject> InfosStation
    {
        get
        {
            return _infosStation;
        }
        set
        {
            _infosStation = value;
        }
    }

    #endregion

    string nameStation;
    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this,
                new PropertyChangedEventArgs(propertyName));
        }
    }

    private ImageSource _logoStation;
    public ImageSource LogoStation
    {
        get
        {
            return _logoStation;
        }
        set
        {
            _logoStation = value;
            NotifyPropertyChanged("LogoStation");
        }
    }

    public Infos(string station)
    {
        nameStation = station;
        getInfos();
    }

    public void getInfos()
    {
        SyndicationContext service = new SyndicationContext(new Uri("http://test/817bee9d-faf4-4680-9d05-e41c2c90ae5a/"));

        IQueryable<SyndicObject> requete = (from objectSki in service.Objects
                                           where objectSki.NOMSTATION == nameStation
                                           select objectSki);

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            InfosStation = new DataServiceCollection<SyndicObject>();
            InfosStation.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(InfoStation_LoadCompleted);   
            InfosStation.LoadAsync(requete);
        }
        );
    }

    void InfoStation_LoadCompleted(object sender, LoadCompletedEventArgs e)
    {
        LogoStation = new BitmapImage(new Uri(@"http://test/upload/" + InfosStation[0].LOGO, UriKind.Absolute));
    }
}

1 个答案:

答案 0 :(得分:0)

通过使用属性设置器,您正在使用NotifyPropertyChanged(正确)告诉绑定到LogoStation的UI已更新。这应该意味着UI最初不显示任何内容,然后在加载完成时显示图像。

除了InfosINotifyPropertyChanged继承之外,您还没有看到自己的观看代码。这意味着事件永远不会被发送。

更新你的班级定义,你应该好好去。