1

I have a class DataGroups defined as follows:

 public DataGroups(String uniqueId, String title, String subtitle, String imagePath, String description)

In my C# code of my Windows 8 app, I use this code to load the on the XAML page

  protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {

            var DataGroups = DataSource.GetGroups((String)navigationParameter);
            this.DefaultViewModel["DGroups"] = DataGroups;
        }

GetGroups is defined as follows

 private ObservableCollection<DataGroups> _allGroups = new ObservableCollection<DataGroups>();
        public ObservableCollection<DataGroups> AllGroups
        {
            get { return this._allGroups; }
        }
    public static IEnumerable<DataGroups> GetGroups(string uniqueId)
        {
            if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");

            return _DataSource.AllGroups;
        }

This returns the full list of Data Groups.

How do I refine a function, to get only the list of data groups with a specific Title to display on the XAML page, using Linq?

Return the list of Data groups where the Title matches a defined value.

1 Answer 1

1
public List<DataGroups> GetDataGroupsByName(string name) {
     return _allGroups.Where(x => x.Title == name);
}
4
  • would this go in the GetGroups?
    – Tester
    Nov 15, 2013 at 2:00
  • @Tester: I have edited my post. I noticed you're using SectorGroups sometimes without ever explaining the connection between SectorGroups and DataGroups. Nov 15, 2013 at 2:02
  • Sorry see above, all should be DataGroups
    – Tester
    Nov 15, 2013 at 2:07
  • In that case my example should work just fine, assuming your DataGroups object exposes a public property. Nov 15, 2013 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.