Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding RIA service results and a list to an ObserverableCollection in Silverlight4 MVVM
    text
    copied!<p>I have an Entity result of <code>List&lt;string&gt;</code> GetTagsData that I need to somehow bind with checkboxes in an ObservableCollection and then to a DataGrid. These checkbox bindings correspond to a dynamic comma delimited string that is a subset of that entity result GetTagsData except it's in a comma delimited string. The user then can uncheck or check each item in the DataGrid and then we call an event handler to basically regenerate the comma delimited string. My question is this, Is there a better way of architecting this solution? I see this as potential problematic to maintain in the future. the only thing that I can't change is the comma delimited string coming in and out. and I have to build it in silverlight. Thanks ahead!</p> <p>Comma Delimited String</p> <pre><code>'Chicago','New York','Boston','Los Angeles' </code></pre> <p>Entity Result for <code>List&lt;string&gt;</code> GetTagsData </p> <pre><code>GetTagsData = SecurityDomainContext.Current.vwBusinessUnits.Select(d =&gt; d.Market).Distinct().ToList(); </code></pre> <p>ObservableCollection Class</p> <pre><code> public class TagsCollection : ViewModelBase { private string _tag; private bool _isSelected; public string Tag { get { return _tag; } set { _tag = value; } } public bool IsSelected { get { return _isSelected; } set { _isSelected = value; } } </code></pre> <p>Now in my ViewModel I am able to iterate the Entity results into the Collection and bind that Collection to the DataGrid.</p> <pre><code>private ObservableCollection&lt;TagsCollection&gt; GetTagsCollection(string colName) { ObservableCollection&lt;TagsCollection&gt; ocTags = new ObservableCollection&lt;TagsCollection&gt;(); foreach (string tag in GetTagsData) { if (DelimitedTagSet.Contains(tag.Trim())) { ocTags.Add(new TagsCollection { Tag = tag, IsSelected = true }); } else { ocTags.Add(new TagsCollection { Tag = tag, IsSelected = false }); } } return ocTags; } </code></pre> <p>Here's what the xaml view looks like <img src="https://i.stack.imgur.com/VAeOI.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload