Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This solution is not great, and it's hack-ish, but it will basically do what you want. I made the listview headers invisible, put a textblock above the listview, and set the text value to the groupitem of the first visible item in the listbox. Hacky, but it's the best I came up with.</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); List&lt;String&gt; colList1 = new List&lt;string&gt;() { "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7" }; List&lt;String&gt; colList2 = new List&lt;string&gt;() { "1", "2", "3", "4", "5", "6" }; ObservableCollection&lt;Data&gt; dataCollection = new ObservableCollection&lt;Data&gt;(); for (var a = 0; a &lt; 100; a++) { Random rnd = new Random(); int min = rnd.Next(5000); int rnd1 = rnd.Next(0, 6); int rnd2 = rnd.Next(0, 5); dataCollection.Add( new Data() { Date = DateTime.Now.AddMinutes(min).ToString("hh:MM tt"), Col1 = colList1[rnd2], Col2 = String.Format("Col2: {0}", "X"), Col3 = colList2[rnd2] } ); } this.DataContext = dataCollection; } public class Data { public string Date { get; set; } public string Col1 { get; set; } public string Col2 { get; set; } public string Col3 { get; set; } } private void grid_ScrollChanged(object sender, ScrollChangedEventArgs e) { if (grid.Items.Count &gt; 0) { HitTestResult hitTest = VisualTreeHelper.HitTest(grid, new Point(5, 5)); System.Windows.Controls.ListViewItem item = GetListViewItemFromEvent(null, hitTest.VisualHit) as System.Windows.Controls.ListViewItem; if (item != null) Head.Text = ((Data)item.Content).Date; } } System.Windows.Controls.ListViewItem GetListViewItemFromEvent(object sender, object originalSource) { DependencyObject depObj = originalSource as DependencyObject; if (depObj != null) { // go up the visual hierarchy until we find the list view item the click came from // the click might have been on the grid or column headers so we need to cater for this DependencyObject current = depObj; while (current != null &amp;&amp; current != grid) { System.Windows.Controls.ListViewItem ListViewItem = current as System.Windows.Controls.ListViewItem; if (ListViewItem != null) { return ListViewItem; } current = VisualTreeHelper.GetParent(current); } } return null; } } </code></pre> <p>XAML:</p> <pre><code>&lt;Window x:Class="header.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="auto" SizeToContent="Width"&gt; &lt;Window.Resources&gt; &lt;CollectionViewSource x:Key="data" Source="{Binding}"&gt; &lt;CollectionViewSource.GroupDescriptions&gt; &lt;PropertyGroupDescription PropertyName="Date"/&gt; &lt;/CollectionViewSource.GroupDescriptions&gt; &lt;/CollectionViewSource&gt; &lt;Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}"&gt; &lt;Setter Property="Visibility" Value="Collapsed" /&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;StackPanel&gt; &lt;TextBlock Name="Head" Grid.Row="0"/&gt; &lt;ListView Name="grid" Grid.Column="0" Grid.Row="1" ItemsSource="{Binding Source={StaticResource data}}" Height="300" ScrollViewer.ScrollChanged="grid_ScrollChanged"&gt; &lt;ListView.View&gt; &lt;GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}"&gt; &lt;GridView.Columns&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Col1}" Width="100"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Col2}" Width="100"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Col3}" Width="100"/&gt; &lt;/GridView.Columns&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;ListView.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.ContainerStyle&gt; &lt;Style TargetType="{x:Type GroupItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid Grid.Row="0"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Background="Beige" FontWeight="Bold" Text="{Binding Path=Name, StringFormat={}{0}}"/&gt; &lt;/Grid&gt; &lt;DockPanel Grid.Row="1"&gt; &lt;ItemsPresenter Grid.Row="2"&gt;&lt;/ItemsPresenter&gt; &lt;/DockPanel&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/GroupStyle.ContainerStyle&gt; &lt;/GroupStyle&gt; &lt;/ListView.GroupStyle&gt; &lt;/ListView&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>EDIT: Fixed ScrollChanged event.</p> <pre><code>private void grid_ScrollChanged(object sender, ScrollChangedEventArgs e) { if (grid.Items.Count &gt; 0) { Point point = new Point(5, 5); foreach(Data lvItem in grid.Items) { HitTestResult hitTest = VisualTreeHelper.HitTest(grid, point); ListViewItem item = GetListViewItemFromEvent(null, hitTest.VisualHit) as System.Windows.Controls.ListViewItem; if (item != null) { Data value = ((Data)item.Content); Head.Text = ((Data)item.Content).Date; break; } else { point.X += 5; point.Y += 5; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload