I have, I think a simple question. I have several buttons and depending on which one is clicked, need to bind data to my DataGrid - for examples if Button1 is clicked, bind fields A-D to the grid; if Button2 is clicked, bind fields E-J to the grid. I have the data binding working fine but can't seem to integrate the buttons to determine which data to bind. The same DataGrid is using no matter which button is pressing but I need to bind different data based on which button is clicked. Any thoughts?
Asked
Active
Viewed 146 times
0
-
Take a look at this question ... http://stackoverflow.com/q/320089/512365. The idea is that you bind your DataGrid columns to a collection of columns which you can change based on which button you click. – KornMuffin Nov 08 '16 at 03:29
1 Answers
0
Use
ToggleButton
instead ofButton
, as they exposeIsChecked
property.Declare a
Freezable
like<DiscreteObjectKeyFrame x:Key="A-D" Value="True"/>
underWindow.Resources
orDataGrid.Resources
.Define
<BooleanToVisibilityConverter x:Key="BooleanToVisCnvKey"/>
underWindow.Resources
orDataGrid.Resources
.Bind
Visibility
ofDataGridColumn
toDiscreteObjectKeyFrame .Value
declared in (2) above, and use aIValueConverter
to convertboolean
toVisibility
.<Window.Resources> <DiscreteObjectKeyFrame x:Key="FlagKey" Value="False"/> <BooleanToVisibilityConverter x:Key="BooleanToVisCnvKey"/> </Window.Resources> ... <DataGrid> ... <DataGridTextColumn Visibility="{Binding Value, Source={StaticResource FlagKey}, Converter={StaticResource BooleanToVisCnvKey}}" ...> ... </DataGrid> ... <ToggleButton ... IsChecked="{Binding Value,Source={StaticResource FlagKey}, Mode=TwoWay}" />

AnjumSKhan
- 9,647
- 1
- 26
- 38