Hi,
Need help solving a Task that returns a Task<IEnumerable<Writing>> so I can fill ObservableCollection<ViewModels.IWritingItemViewModel> Writings for my Design Time Data Page:
<d:Page.DataContext>
<designTimeData:MainPageViewModel />
</d:Page.DataContext>
My constructor does this:
public MainPageViewModel()
{
var writings = this.GetGroupsAsync();
this.Writings = new ObservableCollection<ViewModels.IWritingItemViewModel>();
var viewmodels = writings.Select((x, i) => new WritingItemViewModel
{
Writing = x,
VariableItemSize = (i == 0) ? Common.VariableItemSizes.Writings : Common.VariableItemSizes.Normal,
});
}
My var writings = this.GetGroupsAsync(); is:
public async Task<IEnumerable<Writing>> GetGroupsAsync()
{
await this.GetMenuDataAsync();
return this.Groups;
}
which in turn gets data from:
private async Task GetMenuDataAsync()
{
Uri dataUri = new Uri("ms-appx:///DesignTimeData/MenuData.json");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
string jsonText = await FileIO.ReadTextAsync(file);
JsonObject jsonObject = JsonObject.Parse(jsonText);
JsonArray jsonArray = jsonObject["Groups"].GetArray();
foreach (JsonValue groupValue in jsonArray)
{
JsonObject groupObject = groupValue.GetObject();
Writing group = new Writing(
groupObject["UniqueId"].GetString(),
groupObject["IsHeaderInteractive"].GetBoolean(),
groupObject["ViewType"].GetString(),
groupObject["ModelType"].GetString(),
groupObject["Page"].GetString(),
groupObject["Title"].GetString(),
groupObject["Subtitle"].GetString(),
groupObject["ImagePath"].GetString(),
groupObject["Description"].GetString(),
groupObject["GroupId"].GetString()
);
foreach (JsonValue itemValue in groupObject["WritingMenus"].GetArray())
{
JsonObject itemObject = itemValue.GetObject();
group.WritingMenus.Add(new WritingMenu(
itemObject["UniqueId"].GetString(),
itemObject["Page"].GetString(),
itemObject["Title"].GetString(),
itemObject["Subtitle"].GetString(),
itemObject["ImagePath"].GetString(),
itemObject["Description"].GetString(),
itemObject["Content"].GetString(),
itemObject["WritingsId"].GetString(),
itemObject["GroupId"].GetString(),
Convert.ToInt32(itemObject["Item"].ValueType)
));
}
this.Groups.Add(group);
}
}
and I get this Error:
Error 5 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<App1.DesignTimeData.Writing>>'
does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type
'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<App1.DesignTimeData.Writing>>'
could be found (are you missing a using directive or an assembly reference?)
I'm creating collections of:
public interface IWritingItemViewModel : Common.IVariableSizedItem
{
Models.Writing Writing { get; set; }
}
and my class for creating data is:
public class Writing
{
public Writing(
string uniqueId,
bool isHeaderInteractive,
string templateType,
string viewModelType,
string page,
string title,
string subtitle,
string imagePath,
string description,
string groupId
)
{
this.UniqueId = uniqueId;
this.IsHeaderInteractive = isHeaderInteractive;
this.TemplateType = templateType;
this.ViewModelType = viewModelType;
this.Page = page;
this.Title = title;
this.Subtitle = subtitle;
this.ImagePath = imagePath;
this.Description = description;
this.GroupId = groupId;
this.WritingMenus = new ObservableCollection<WritingMenu>();
}
public string UniqueId { get; private set; }
public bool IsHeaderInteractive { get; private set; }
public string TemplateType { get; private set; }
public string ViewModelType { get; private set; }
public string Page { get; private set; }
public string Title { get; private set; }
public string Subtitle { get; private set; }
public string ImagePath { get; private set; }
public string Description { get; private set; }
public string GroupId { get; private set; }
public virtual ObservableCollection<WritingMenu> WritingMenus { get; private set; }
}
How can I solve or successfully complete this code?
Thanks!...
Code is like a box of chocolates!...
No comments:
Post a Comment