Suggestion for controls

Apr 28, 2015 at 9:05 PM
Edited Apr 29, 2015 at 4:20 AM

I´m looking for controls they works with your Framework-Architecture. I think a need follwing two controlls:

1) AllocationListBoxes
I want to assign Users to Usergroups. So I can select a Usergroup from a DataGrid. Then the CustomControl show two Listboxes: On the left-side all users that are in the selected group and on the right-side all users that can be selected. I a User double-click or presse a "add"-button then the selected username from the right-side go to left side and the command for process this information for the database will raised

2) AllocationCheckBoxes
I want to assign UserRoles to UserGroups. I select as Usergroup like above. Then in a list of Checkboxes all possible UserRoles are shown and the selected are marked as checked. I a user check/uncheck a userrole then the information is stored to database (fired a command)

As Datalayer/ORM I using EF6. And the data is stored in Linkedtables (UserTable - UserGroupTable - UsersToUserGroupsTable)

Did someone know Controls like i descripe? Or have someone a good idea how can i do that in a WPF/MVVM Application with the CODE.Framework?

Thanks for your help
Apr 30, 2015 at 7:48 AM

You don't need any custom controls to do this.

For scenario #1, you can simply create a view model with two lists. One that contains all the available items and the other the one you select it. When the user clicks "Add", you bind that to a command/viewAction that takes the selected item from the first list and moves it into the second. The XAML code could look something like this:
<ListBox ItemsSource="{Binding AvailableGroups}" SelectedItem="{Binding SelectedAvailableGroup}" />
<Button Content="Add" Command="{Binding AddGroup}" />
<ListBox ItemsSource="{Binding IncludedGroups}" SelectedItem="{Binding SelectedIncludedGroup}" />
The AddGroup command can then be implemented like this:
AddGroup = new ViewAction(execute: (a, o) => {
You should add a little more code of course to make sure there is a selected item and such, but I think you get the idea.

For scenario #2, you can simply create yourself a list of items that include a boolean property (for selection) and another for the display name. You then bind that to a listbox and create item templates for the listbox that includes a checkbox and a label. Here's a conceptual code example:
<ListBox ItemsSource="{Binding AvailableGroups}">
            <CheckBox IsChecked="{Binding GroupSelected}" Content="{Binding GroupName}" />