0

I have a datagrid like this:

<DataGrid x:Name="MeasureDataGrid" CanUserAddRows="False" AutoGenerateColumns="False" IsReadOnly="True">
                <DataGrid.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="{x:Type GroupItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                            <Expander x:Name="Expander" IsExpanded="True" Background="DarkBlue">
                                                <Expander.Header>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="{Binding Name}" Foreground="AntiqueWhite"/>
                                                        <TextBlock Text="{Binding ItemCount, StringFormat=Count: {0}}" Margin="30,0,0,0" Foreground="AntiqueWhite"/>
                                                    </StackPanel>
                                                </Expander.Header>
                                                <StackPanel>
                                                    <ItemsPresenter />
                                                </StackPanel>
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <DockPanel Background="LightBlue">
                                    <TextBlock Text="{Binding Name}" Foreground="Blue" Margin="30,0,0,0" Width="100"/>
                                    <TextBlock Text="{Binding Path=ItemCount}" Foreground="Blue"/>
                                </DockPanel>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </DataGrid.GroupStyle>

                <DataGrid.Columns>
                    <DataGridTextColumn Header="ID" Binding="{Binding Id}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Main Emotion" Binding="{Binding MainEmotion}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Main Type" Binding="{Binding MainType}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Tempo" Binding="{Binding MeasureParameterModel.Tempo}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Key" Binding="{Binding MeasureParameterModel.Key}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Accidental" Binding="{Binding MeasureParameterModel.Accidental}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Mode" Binding="{Binding MeasureParameterModel.Mode}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Trend" Binding="{Binding MeasureParameterModel.Trend}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Beats" Binding="{Binding MeasureParameterModel.Beats}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Beat Type" Binding="{Binding MeasureParameterModel.BeatType}"></DataGridTextColumn>
                    <DataGridTextColumn Header="First Note" Binding="{Binding Measure[0].Note[0].Pitch.Step}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Alter" Binding="{Binding Measure[0].Note[0].Pitch.Alter}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Octave" Binding="{Binding Measure[0].Note[0].Pitch.Octave}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Measure Count" Binding="{Binding Measure.Count}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Instrument" Binding="{Binding MeasureParameterModel.Instrument}"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

I want to see every groups Beats*BeatType value as a text block in the expander header. Beats and BeatType values are a column of the datagrid and as an example i bind Beats value like this:

{Binding MeasureParameterModel.Beats}

How to bind the Beats*BeatType value on a text Block in Expander ?

Edit: I use a converter to produce the value to show in the datagrid groups. I use this Converter example as a template: WPF DataGrid Grouping with sums and other fields

Ege
  • 138
  • 1
  • 14
  • I'm assuming the datatype for Beats is an `int`. But what is the datatype for BeatType? Are you trying to multiply them together to get a new number to display in the Expander, or are you just trying to print a string in the Expander that says something like "2*DownBeat"? – Tam Bui Jun 27 '20 at 20:26
  • Secondly, it would help to see the classes you are binding to (MeasureParameterModel and whatever the main binding class is that holds that instance). I'm a little weary because based on your bindings, it looks to me like you are binding directly to your Model classes (e.g. MeasureParameterModel) instead of creating a ViewModel class to bind to. – Tam Bui Jun 27 '20 at 20:29

0 Answers0