Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I've got a DataGrid with a number of columns, which I've manually defined in xaml.
XML
<DataGrid ItemsSource="{Binding SearchResult}" AutoGenerateColumns="False">
       <DataGridTextColumn Header="Column1" Binding="{Binding Property1}" />
       <DataGridTextColumn Header="Column2" Binding="{Binding Property2}" />
        ...
</DataGrid>


Now I'd like to have a ContextMenu in which each column has a MenuItem with checkbox to hide or show the Column.
XML
<ConextMenu ItemSource="{Binding Columns}">
   <MenuItem>
      <MenuItem.Icon><CheckBox IsChecked="{Binding IsVisible}" /></MenuItem.Icon>
      <MenuItem.Header><TextBlock Text="{Binding ColumnHeader}" /></MenuItem.Header>
   </MenuItem>
   ....
</ContextMenu>


How can I implement this with Bindings?

Thanks a lot for your reply.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900