Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: MVVM Event Aggregator and WCF Service. Not updating The UI

$
0
0

My ViewModel

namespace Chameleon.Navigation.ViewModel
{
    public class TopMenuViewModel : NotificationObject
    {
        IEventAggregator _eventAggregator;
        Dispatcher _dispatcher;
        public DelegateCommand<object> LoadMenuCommand { get; private set; }

        ObservableCollection<NavigationMenuHeader> pickableCollection;

        public TopMenuViewModel(IEventAggregator evt, IRegionManager regionManager, Dispatcher dis)
        {
            this._eventAggregator = evt;
            this._dispatcher = dis;
     
            PickableCollection = new ObservableCollection<NavigationMenuHeader>();

            //Broadcast logging event 
            Chameleon.Common.CommonAgent.IsLoggedIn loggingIn = _eventAggregator.GetEvent<Chameleon.Common.CommonAgent.IsLoggedIn>();
            _eventAggregator.GetEvent<Chameleon.Common.CommonAgent.IsLoggedIn>().Subscribe(OnLoggedIn, ThreadOption.UIThread, false);

        }

        public ObservableCollection<NavigationMenuHeader> PickableCollection
        {
            get { return this.pickableCollection; }
            set
            {
                this.pickableCollection = value;
                this.RaisePropertyChanged(() => this.PickableCollection);
               // OnPropertyChanged("PickableCollection");

            }
        }

        public void OnLoggedIn(bool e)
        {
            BusinessService.NavigationBusiness bus = new BusinessService.NavigationBusiness();
            
            bus.GetMenuHeaderCompleted += (svr) =>
            {
                if (svr != null)
                {
                    _dispatcher.BeginInvoke(() =>
                        {
                            PickableCollection.Clear();
                            PickableCollection = (ObservableCollection<NavigationMenuHeader>)svr;
                        });
                }
            };

            bus.GetMenuHeader(1);
        }

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>