C#C
C#14mo ago
1 reply
Delicious Cake

ListView column help (How to autosize, align content and add column lines?)

This is my current GUI (Using ModernWpf), I've done a lot of Googling and I can't seem to find a way to do the following:

1) Vertically align the text in the 'Name' column to be centered
2) Horizontally align the ComboBox in the 'Voice' column to be centered
3) Make the ComboBoxes to automatically have the size of the longest option
4) Add vertical line separators between the columns all the way down

And here is one of the ListViews as an example (they're both identical just different ItemSources)
<ListView x:Name="ChatterListView" Grid.Row="1" ItemsSource="{Binding Source={StaticResource ChattersSort}}" HorizontalAlignment="Stretch">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name" Width="Auto" DisplayMemberBinding="{Binding Username}"/>

            <GridViewColumn Header="Voice" Width="Auto">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Grid>
                            <ComboBox ItemsSource="{Binding DataContext.Voices, RelativeSource={RelativeSource AncestorType=Window}}"
                                      SelectedItem="{Binding Voice, Mode=TwoWay}"
                                      DisplayMemberPath="Name" Width="Auto" />
                        </Grid>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

            <GridViewColumn Header="Enabled" Width="75">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox IsChecked="{Binding TTSEnabled, Mode=TwoWay}" Unchecked="ChatterCheckBox_Unchecked" Checked="ChatterCheckBox_Checked"/>
                        </StackPanel>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
image.png
Was this page helpful?