I am having problems getting a listview with a gridview to align the text within a cell. I downloaded the SDK sample "ListView That Uses a GridView with Templates Sample" from http://msdn2.microsoft.com/en-us/library/ms771780.aspx This includes a cell template that uses: <DataTemplate x:Key="myCellTemplateYear"> <DockPanel> <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center"> <TextBlock.Text> <Binding Path="Year"/> </TextBlock.Text> </TextBlock> </DockPanel> </DataTemplate> I would expect this to align the "Year" in the "Center" of each cell. But this does not happen - it is always "Left" aligned. Is this a bug in WPF or in the SDK sample? Any hints on how to modify the sample to Right justify the Year would be greatly appreciated. Thanx
The ListViewItems that contain your cells default to Left content alignment. You can override that with this: <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> </Style> </ListView.ItemContainerStyle> "keithabarker" wrote: > I am having problems getting a listview with a gridview to align the text > within a cell. > > I downloaded the SDK sample "ListView That Uses a GridView with Templates > Sample" from http://msdn2.microsoft.com/en-us/library/ms771780.aspx > > This includes a cell template that uses: > > <DataTemplate x:Key="myCellTemplateYear"> > <DockPanel> > <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center"> > <TextBlock.Text> > <Binding Path="Year"/> > </TextBlock.Text> > </TextBlock> > </DockPanel> > </DataTemplate> > > I would expect this to align the "Year" in the "Center" of each cell. > But this does not happen - it is always "Left" aligned. > > Is this a bug in WPF or in the SDK sample? > > Any hints on how to modify the sample to Right justify the Year would be > greatly appreciated. > > Thanx >