简体   繁体   中英

Updating UI in WPF project after calling WCF service async

I have a following problem.

client.GetServiceMapCompleted += (s, e) =>
            {
                this.MyServiceMap = e.Result;

                this.MyServiceMap.Categories.Add(new Category() { Name = " " });
                this.MyServiceMap.Groups.Add(new Group() { Name = " " });

                this.MyServiceMap.Groups.Sort((a, b) =>
                    {
                    return String.Compare(a.Name, b.Name);
                    });
                this.MyServiceMap.Categories.Sort((a, b) =>
                    {
                        return String.Compare(a.Name, b.Name);
                    });

                this._parents = MyServiceMap.Nodes;
                this._children = MyServiceMap.Nodes;
            };

        client.GetServiceMapAsync(); 

I have MyServiceMap, Parents and Children properties:

    private ServiceMap _serviceMap;
    public ServiceMap MyServiceMap
    {
        get
        {
            return _serviceMap;
        }
        set
        {
            _serviceMap = value;
            OnPropertyChanged("MyServiceMap");
        }
    }

    private List<Node> _parents;
    public List<Node> Parents
    {
        get
        {
            return _parents;
        }
        set
        {
            _parents = value;
            OnPropertyChanged("Parents");
        }
    }

    private List<Node> _children;
    public List<Node> Children
    {
        get
        {
            return _children;
        }
        set
        {
            _children = value;
            OnPropertyChanged("Children");
        }
    }

In UI i bind MyServiceMap to datagrid, Children and Parents to a listbox.

In a datagrid i see everything as supposed, but children and parents listbox field remains empty.

My question is why my UI is not refreshed after async calling and how to solve that?

Tnx in advanced :)

You're setting the fields and not the properties (where you raise the PropertyChanged ) so your UI does not get notified about changes.

this._parents = MyServiceMap.Nodes;
this._children = MyServiceMap.Nodes;

should be

Parents = MyServiceMap.Nodes;
Children = MyServiceMap.Nodes;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM