tags:

views:

126

answers:

2

I'm still learning WPF, but I'm really confused about something that should be really simple. What I want to do is to center the contents of the 3rd and 4th columns. When I run this, the columns are left justified.

        <ListView Margin="0" x:Name="listMonitoredUrls" AlternationCount="1"
              ItemsSource="{Binding}"  >
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Description" DisplayMemberBinding="{Binding FriendlyDesc}"/>
                <GridViewColumn Header="Url" DisplayMemberBinding="{Binding Url}"/>
                <GridViewColumn Header="Frequency"   >
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <TextBlock Text="{Binding ScanFrequencyMinutes}"  HorizontalAlignment="Center"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Next Scan"  >
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <TextBlock Text="{Binding TimeNextScanStr}"  HorizontalAlignment="Center"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

I"m really starting to like WPF, but some simple things like this seem to be really hard.

A: 

Try using the TextAlignment property instead of HorizontalAlignment - should do it. To my understanding HorizontalAlignment="Center" will center your textblock not the text in it.

JohnIdol
That was what I used in my first attempt. It doesn't work either. Sorry for not putting that in my initial posting.
photo_tom
does it work if you aling left or right? check this link and see if you can spot differences with your xaml --> http://social.msdn.microsoft.com/forums/en-US/wpf/thread/1f17a5a6-c71f-4810-b8bc-e4eb2a25fa96/
JohnIdol
A: 

This might be a long shot but i've had to do it for listboxes where the items are defined by templates. Try setting the HorizontalContentAlignment="Stretch" on your ListView. If I don't set that the items take only as much space as they need and are left justified.

AndyG