lundi 23 février 2015

Checked event firing when grouping added to DataGrid - WPF C#

I'm having a problem where when adding grouping to my datagrid; the event I have defined as "Checkbox.Checked" gets called when it shouldn't be. When this line of code is not commented out "collection.GroupDescriptions.Add(new PropertyGroupDescription("_group"));" the bug occurs.


Upon starting my application with this line in, the first check of any checkbox works as it should, then on the second click, if I click literally anywhere on the datagrid, the checked event will be fired.


Do any of you Stack Overflow geniuses have any idea?


Thanks.


I have events define on my DataGrid like this;



<DataGridCheckBoxColumn.CellStyle>
<Style>
<EventSetter Event="CheckBox.Checked" Handler="Method_checked"/>
<EventSetter Event="CheckBox.Unchecked" Handler="Method_Unchecked"/>
</Style>
</DataGridCheckBoxColumn.CellStyle>


I have since added grouping to my data using the following code in C#;



ListCollectionView collection = new ListCollectionView(listOfData);
collection.GroupDescriptions.Add(new PropertyGroupDescription("_group"));
dgData.ItemsSource = collection;


I have added groups to my datagrid adding the following code in xaml;



<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>


You may noticed "GroupHeaderStyle" which is defined above;



<Window.Resources>
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="exp" IsExpanded="True"
Background="White"
Foreground="Black">
<Expander.Header>
<TextBlock Text="{Binding Name}" />
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>




Aucun commentaire:

Enregistrer un commentaire