Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

.Net WPF XAML How to Style GridViewColumns

$
0
0

I'm using a ListView which implements a GridView and am having a lot of trouble figuring out how to Style my GridViewColumn content.  Here is the XAML:

<ListView ItemsSource="{Binding Path=SelectedEmployee.NotificationBase.Notifications}" SelectedItem="{Binding SelectedNotification}"
                  Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" SelectionMode="Single"
                  HorizontalContentAlignment="Stretch" BorderBrush="Black" BorderThickness="1"><ListView.View><GridView><GridViewColumn Width="600"><GridViewColumn.Header><TextBlock Text="Notification Text" Width="600"/></GridViewColumn.Header><GridViewColumn.CellTemplate><DataTemplate><TextBlock TextWrapping="Wrap" Text="{Binding NotificationText}"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumn Width="120"><GridViewColumn.Header><TextBlock Text="Acknowledge" HorizontalAlignment="Center"/></GridViewColumn.Header><GridViewColumn.CellTemplate><DataTemplate><Button Command="{Binding Path=DataContext.AcknowledgeNotification, 
                                                RelativeSource= {RelativeSource FindAncestor,
                                                AncestorType={x:Type ListView}}}"
                                        Content="Ok" HorizontalAlignment="Center"
                                        CommandParameter="{Binding}"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View></ListView>

In doing some screwing around, I've kind of figured out that I'm not able to style either of my headers or content of the columns not matter what I try.  For some reason, the "Acknowledge" header appears to Center even if I changed the HorizonalAlignment to "Right"... no idea why that is.  Attempting to add any kind of HorizontalAlignment to my first Column header or content seems to do nothing either.  In what I've found online, it seems like I need to construct DataTemplate Styles to get this to work.  At this point, it seems like so much more trouble than it's worth when I've had better luck with DataGrids.  The one thing I don't like about the DataGrid is that when you use a button like the scenario I have, you have to click it twice to "run" it.  Is there not a relatively easy way to style GridViewColumns?  All I'm looking to do is Center the Button in my "Acknowledge" column.

Thanks for the help!!


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>