I'm currently working on refactoring some old code that was written on top of WPF with C #.
I currently have a composite user model that looks like this:
public class UserModel{
public User User {get; set;}
public List<Guid> Permissions {get; set;}
}
In this model, the permission list is a list of permission identifiers granted to the user that the model refers to.
In my xaml for my user control screen, I have a list of these models associated with the combo box, and when the selection changes, the selected item is tied to a grid containing text fields for the User property and the control.
The item control is populated with checkboxes tied to all permissions on the systems when the page loads. My question is the best way to bind a list of permissions to checkboxes in an item control?
The code for the control looks something like this:
<ScrollViewer Grid.Row="7" Grid.Column="1">
<ItemsControl ItemsSource={Binding}>
<ItemsControl.ItemsTemplate>
<DataTemplate>
<Checkbox Content="{Binding Description}" IsChecked="{Binding IsSelected}"/>
</DataTemplate>
</ItemsControl.ItemsTemplate>
</ScrollViewer>
And the permission set is a list of this object:
class SelectedPermission{
public Guid PermissionId {get; set;}
public string Description {get; set;}
public bool IsSelected {get; set;}
}
My initial thought was to implement INotifyPropertyChanged in the SelectedPermission collection, and when I bind my user, just set IsSelected to true for any permissions granted to the selected user. But there seems to be a better way.
source
share