コード例 #1
0
        /// <summary>
        /// Costruttore.
        /// </summary>
        public HomeViewModel(IDataAccessDb db)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"

                // INIT
                this.nuovaSchedina = new Schedina()
                {
                    Title = Resources.AppResources.PanoramaPivot1ItemTitle
                };
                this.schedine = new ObservableCollection <Schedina>();

                // DB
                this.dataAccessDb = db;

                // RELAY COMMAND
                NavToPageCommand = new RelayCommand <Schedina>((s) =>
                {
                    if (s != null)
                    {
                        System.Diagnostics.Debug.WriteLine("[HOMEVIEWMODEL] " + "Tapped NavToPageCommand: " + s.Title.ToString());
                        string pageName      = "SchedinaView";
                        string pageParameter = s.Title.ToString();

                        Messenger.Default.Send <NavToPage>(new NavToPage {
                            PageName = pageName, PageParameter = pageParameter
                        });
                    }
                });

                DeleteSchedinaCommand = new RelayCommand <Schedina>(async(s) =>
                {
                    if (s != null && s.GetType() == typeof(Schedina))
                    {
                        System.Diagnostics.Debug.WriteLine("[HOMEVIEWMODEL] " + "Tapped DeleteCommand: " + s.Title.ToString());
                        bool isDeleted = await dataAccessDb.DeleteSchedina(s.Id);
                        if (isDeleted)
                        {
                            Schedine.Remove(s);
                        }
                        else
                        {
                            // TODO
                            // Notificare l'errore nella UI.
                        }
                    }
                });

                RefreshBindingData = new RelayCommand(PopolaPanoramaProperties);
            }
        }
コード例 #2
0
        /// <summary>
        /// Consente di popolare le proprieta' in binding con il Panorama.
        /// </summary>
        public async void PopolaPanoramaProperties()
        {
            // Pivot 2
            var listSchedineFromDb = await dataAccessDb.GetSchedine();

            foreach (Schedina s in listSchedineFromDb)
            {
                if (!Schedine.Contains(s))
                {
                    Schedine.Add(s);
                }
            }
        }