forum

Home / DeveloperSection / Forums / WPF Binding Checkbox Content and IsChecked to Different Lists

WPF Binding Checkbox Content and IsChecked to Different Lists

Mark Devid548624-Sep-2013

I have an issue with binding multiple properties to a single control. I have two lists called UserList and GroupList. I'm trying to display a ListView of checkboxes of all the groups in the system. The UserList object contains a list of integers based on the ID of the groups it is a member of. I'd like to have the checkboxes be checked if the UserList object contains an ID of a group in the groupList.

For example, the GroupList might contain IDs 1,2,3,4. While the UserList has a list of IDs of 1 and 3. I'd therefore like checkboxes 1 and 3 checked, but 2 and 4 unchecked.

To do this, I need to bind to two different properties at the same time and possible have some kind of converter. I'm pretty new to this stuff, so I'm kind of stuck as to what to try next. Here's what I've currently got -

<ListView Name="ListBox1"

Grid.Row="1"

Margin="30,4,30,22"

FontFamily="Segoe UI"

FontSize="14"

ItemsSource="{Binding GroupList,

UpdateSourceTrigger=PropertyChanged}">

<ListView.ItemTemplate>

    <DataTemplate>

        <CheckBox Margin="2"

                  Content="{Binding Name}"

                  IsChecked="{Binding Source={StaticResource UserGroupDataProvider}}" />

    </DataTemplate>

</ListView.ItemTemplate>

Obviously I'm missing some kind of static resource, but I'm not sure what to do with that.

Any advice would be appreciated.


Updated on 24-Sep-2013

Can you answer this question?


Answer

1 Answers

Liked By