0

基本问题,我想从 Azure 服务器加载数据并查看将其发送到 XAML。可以是 ListBox 或 LongListSelector(最佳选择)。你能更正我的代码吗?我究竟做错了什么?

从 Azure 加载数据并将其发送到 IEnumerable 集合。

视图模型

             public class ViewModel : INotifyPropertyChanged
                {
                    private readonly ICommand _loadDataCommand;
                    private MobileServiceCollection<ModelAzure, ModelAzure> _items;
                    public event PropertyChangedEventHandler PropertyChanged;
                    public IEnumerable itemsControl;

              private async void RefreshTodoItems()
                {
                    try
                    {
                        _items = await _todoTable.ToCollectionAsync();
                    }
                    catch (MobileServiceInvalidOperationException e)
                    {
                        MessageBox.Show(e.Message, "Error loading items, please try again :)", MessageBoxButton.OK);
                    }
                   itemsControl = _items;
                }



                public ICommand LoadDataCommand
                {
                    get { return this._loadDataCommand; }
                }

                private void LoadDataAction(object p)
                {
                    RefreshTodoItems();
                }

                public IEnumerable AzureData
                {
                    get
                    {
                        return itemsControl;
                    }
                    set
                    {
                        itemsControl = value;
                        RaisePropertyChanged("AzureData");
                    }
                }

         private void RaisePropertyChanged(string propertyName)
            {
                PropertyChangedEventHandler handler = this.PropertyChanged;
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
                }
            }
}

XAML

<ListBox Grid.Column="0" Margin="5"
                 ItemsSource="{Binding AzureData}"
                 DisplayMemberPath="Text" Height="180"
                 />
4

1 回答 1

1

您需要使用 setter 设置 AzureData.. 而不仅仅是私有支持变量,以便触发 RaisePropertyChanged 事件。

AzureData = _items;
于 2013-10-14T23:38:23.113 回答