1

I have this issue that i can't figure out.

I have a ListView with grades (specific student, specific subject). Now, I have Horizontal ListView like this:

<ListView 
x:Name="gradeListView"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True"
SelectionChanged="gradeListView_SelectionChanged" 
Grid.ColumnSpan="3" 
Grid.Row="2"
Margin="30,153,325,-194" 
>
<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Background="Transparent" Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.View>
    <GridView>
        <GridView.Columns>
            <GridViewColumn DisplayMemberBinding="{Binding Mark}" Header="Ocena" />
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Tag="{Binding Id}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView.Columns>
    </GridView>
</ListView.View>

This code gives me:

enter image description here

What i want is:

enter image description here

Can I somehow wrap this checkbox and Mark into vertically stack elements in the same column? I tried to do this myself but failed.

Please, be understanding, this is my first WPF project with custom controls etc. :)

Thank You in advance for your help.

Bizhan
  • 16,157
  • 9
  • 63
  • 101
bmrki
  • 371
  • 3
  • 15
  • Possible duplicate of [WPF horizontal DataGrid](https://stackoverflow.com/questions/4132829/wpf-horizontal-datagrid) – Bizhan Jun 10 '18 at 12:12

1 Answers1

1

If you don't want to rotate the control (as in WPF horizontal DataGrid) You can merge two columns into a stack panel:

    <ListView.View>
        <GridView>
            <GridView.Columns>
                <GridViewColumn Header="Ocena">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}" />
                                <TextBlock Text="{Binding Mark}"/>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView.Columns>
        </GridView>
    </ListView.View>
Bizhan
  • 16,157
  • 9
  • 63
  • 101