Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm guessing your Item source of AllPermissions is a collection of Permission objects. So just make sure that in addition to the DisplayName that it also has something on there that determines whether the role has the permission:</p> <pre><code>public class Permission : ViewModelBase { private string displayName; private bool roleHasPermission; public string DisplayName { get { return this.displayName; } set { this.displayName = value; this.RaisePropertyChanged(() =&gt; this.DisplayName); } } public bool RoleHasPermission { get { return this.roleHasPermission; } set { this.roleHasPermission = value; this.RaisePropertyChanged(() =&gt; this.RoleHasPermission); } } } </code></pre> <p>so then Bind IsChecked to RoleHasPermission.</p> <p>Now I'm guessing at the moment that you are loading the available permissions from somewhere and they are currently ignorant of if the role has thepermission, so when you are loading the AllPermissions, calculate whether the rolehas the permission.</p> <p>I have assumed you have inherited from a base class that has a RaisePropertyChanged event on it to notify the view when the value has been updated. (such as provided for you if you use mvvm light or other frameworks, or you can write your own) Also if you want to be able to edit the permission by checking/unchecking the check box, then remember to set the binding Mode=TwoWay ie:</p> <pre><code>&lt;ListBox ... ItemsSource="{Binding AllPermissions}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;CheckBox Content="{Binding DisplayName}" IsChecked="{Binding RoleHasPermission, Mode=TwoWay}"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; </code></pre> <p></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