Asked by:
Customized Method is not working for SampleDataSource.cs class

Question
-
Hi
I want to get all Group items from _sampleDataSource.AllGroups i have changed the existing GetItems method but it returns null value every time. I’m new to this lambda expression. Anyone can help me out?
public static SampleDataItem GettopItems()
{
// Simple linear search is acceptable for small data sets
var matches = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.Group.Equals("Pictures"));
if (matches.Count() == 1) return matches.First();
return null;
}
Kind regards
Radika
- Edited by Radika Thursday, October 3, 2013 10:10 AM
Thursday, October 3, 2013 8:18 AM
All replies
-
Can you post the list of items that you are selecting from?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Thursday, October 3, 2013 2:22 PMModerator -
Hi Matt
Thanks for respond
sorry for not listing all the code snippet. Instead of LoadImage() method and GetTileItem(string uniqueId) (heighted) other codes are there with the sample datasouce.cs comes with the grid template
public sealed class SampleDataSource
{
private static SampleDataSource _sampleDataSource = new SampleDataSource();
private ObservableCollection<SampleDataGroup> _allGroups = newObservableCollection<SampleDataGroup>();
public ObservableCollection<SampleDataGroup> AllGroups
{
get { return this._allGroups; }
}
public static IEnumerable<SampleDataGroup> GetGroups(string uniqueId)
{
if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");
return _sampleDataSource.AllGroups;
}
public static SampleDataGroup GetGroup(string uniqueId)
{
// Simple linear search is acceptable for small data sets
var matches = _sampleDataSource.AllGroups.Where((group) => group.UniqueId.Equals(uniqueId));
if (matches.Count() == 1) return matches.First();
return null;
}
public static SampleDataItem GetItem(string uniqueId)
{
// Simple linear search is acceptable for small data sets
var matches = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals("CaptureGroup-1"));
if (matches.Count() == 1) return matches.First();
return null;
}
public static SampleDataItem GetTileItem(string uniqueId)
{
// Simple linear search is acceptable for small data sets
var matches = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));
if (matches.Count() == 1)
{
var match = matches.First();
// UpdateContent(match);
return match;
}
return null;
}
public SampleDataSource()
{
LoadImage();
}
//Following method accessing the Picture library and create bit map image using URI s and add that to default SampleDataItems
private async void LoadImage()
{
try
{
IReadOnlyList<Windows.Storage.StorageFile> resultsLibrary =
await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();
var group4 = new SampleDataGroup("Group-4",
"Pictures",
"Group Subtitle: 1",
resultsLibrary[0].Path,
"Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");
foreach (var item in resultsLibrary)
{
//new Movie {Title = item.Title,Category = item.Category,Subtitle = "The Towani family civilian shuttlecraft crashes on the forest moon of Endor.", Image = item.Category
//Movies.Add(new Movie { Title = item.Title, Category = item.Category, Subtitle = item.Subtitle, Image = item.Image });
//};
Windows.Storage.Streams.IRandomAccessStream imageStream =
await item.OpenAsync(Windows.Storage.FileAccessMode.Read);
Windows.UI.Xaml.Media.Imaging.BitmapImage imageBitmap =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
imageBitmap.SetSource(imageStream);
SampleDataItem sdata = new SampleDataItem(item.DisplayName + "Group-1",
item.Path,
"2278.59",
null,
"Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
item.Name,
47,
16,
group4);
sdata.Image = imageBitmap;
group4.Items.Add(sdata);
}
this.AllGroups.Add(group4);
}
catch (Exception ex)
{
// MessageBlock.Text += "Exception encountered: " + ex.Message + "\n";
}
}
My problem is I have added above method(yellow) to get top 5 items to render in my grouped item page to pass it to tile notifications my problem is that above method Is return null, is I’m missing something or any way I could get top 5 items to grouped item page XAML.
Note: I have used VS 2012 provided grid app template therefor same XAML formats are used in this Case
Kind regards
Radika
- Edited by Radika Friday, October 4, 2013 4:28 AM
Friday, October 4, 2013 4:26 AM