lundi 19 décembre 2016

Change visibility of one itemscontrol via checkbox in another

I have two ItemsControls with the same ItemsSource. One has some controls for each item, the other has a checkbox for each item. The controls in them are dynamically added. How can I bind the visibility of the first ItemsControls to the corresponding checkbox in the other ItemsControls ?

Here's the first ItemsControl containing multiple TextBlocks in the row. Note: I want to hide the whole row of controls.

<ItemsControl ItemsSource="{Binding VehicleCollection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
               <TextBlock  />
               <TextBlock  />
               <TextBlock  />
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Here's the second ItemsControl with the checkboxes:

<ItemsControl ItemsSource="{Binding VehicleCollection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <CheckBox Content="{Binding Name}"
                          IsChecked="True" />
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

So what happens is, for each item in VehicleCollection, a new row of textblocks is added for the first ItemsControl, and a checkbox is added for the second ItemsControl. These should relate to each other for example: If I uncheck the first checkbox, the first row for the other ItemsControl should be hidden.

I know how to do the booltovis converter, just not sure on how to relate these two ItemsControls.




Aucun commentaire:

Enregistrer un commentaire