@@ -1846,7 +1846,7 @@ public View View
1846
1846
1847
1847
if ( IsHandleCreated && _viewStyle == View . Details )
1848
1848
{
1849
- ApplyColumnHeaderDarkModeOnDemand ( ) ;
1849
+ ApplyDarkModeOnDemand ( ) ;
1850
1850
}
1851
1851
1852
1852
UpdateListViewItemsLocations ( ) ;
@@ -4537,8 +4537,6 @@ protected override void OnHandleCreated(EventArgs e)
4537
4537
PInvokeCore . SendMessage ( this , PInvoke . CCM_SETVERSION , ( WPARAM ) 5 ) ;
4538
4538
}
4539
4539
4540
- ApplyColumnHeaderDarkModeOnDemand ( ) ;
4541
-
4542
4540
UpdateExtendedStyles ( ) ;
4543
4541
RealizeProperties ( ) ;
4544
4542
PInvokeCore . SendMessage ( this , PInvoke . LVM_SETBKCOLOR , ( WPARAM ) 0 , ( LPARAM ) BackColor ) ;
@@ -4599,6 +4597,7 @@ protected override void OnHandleCreated(EventArgs e)
4599
4597
}
4600
4598
4601
4599
int columnCount = _columnHeaders is null ? 0 : _columnHeaders . Length ;
4600
+
4602
4601
if ( columnCount > 0 )
4603
4602
{
4604
4603
int [ ] indices = new int [ columnCount ] ;
@@ -4644,6 +4643,7 @@ protected override void OnHandleCreated(EventArgs e)
4644
4643
// When the handle is recreated, update the SavedCheckedItems.
4645
4644
// It is possible some checked items were added to the list view while its handle was null.
4646
4645
_savedCheckedItems = null ;
4646
+
4647
4647
if ( ! CheckBoxes && ! VirtualMode )
4648
4648
{
4649
4649
for ( int i = 0 ; i < Items . Count ; i ++ )
@@ -4654,21 +4654,48 @@ protected override void OnHandleCreated(EventArgs e)
4654
4654
}
4655
4655
}
4656
4656
}
4657
+
4658
+ if ( ! RecreatingHandle )
4659
+ {
4660
+ ApplyDarkModeOnDemand ( ) ;
4661
+ }
4657
4662
}
4658
4663
4659
- private void ApplyColumnHeaderDarkModeOnDemand ( )
4664
+ #pragma warning disable WFO5001
4665
+ private void ApplyDarkModeOnDemand ( )
4660
4666
{
4661
- #pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
4662
4667
if ( Application . IsDarkModeEnabled )
4663
4668
{
4664
- _ = PInvoke . SetWindowTheme ( HWND , $ "{ DarkModeIdentifier } _{ ExplorerThemeIdentifier } ", null ) ;
4669
+ // Enable double buffering when in dark mode to reduce flicker.
4670
+ uint exMask = PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_TWOCLICKACTIVATE |
4671
+ PInvoke . LVS_EX_TRACKSELECT | PInvoke . LVS_EX_UNDERLINEHOT |
4672
+ PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_HEADERDRAGDROP |
4673
+ PInvoke . LVS_EX_CHECKBOXES | PInvoke . LVS_EX_FULLROWSELECT |
4674
+ PInvoke . LVS_EX_GRIDLINES | PInvoke . LVS_EX_INFOTIP | PInvoke . LVS_EX_DOUBLEBUFFER ;
4675
+
4676
+ uint exStyle = BuildExStyleInternal ( ) ;
4677
+ exStyle |= PInvoke . LVS_EX_DOUBLEBUFFER ;
4678
+
4679
+ PInvokeCore . SendMessage (
4680
+ this ,
4681
+ PInvoke . LVM_SETEXTENDEDLISTVIEWSTYLE ,
4682
+ ( WPARAM ) exMask ,
4683
+ ( LPARAM ) exStyle ) ;
4684
+
4685
+ // Apply dark mode theme to the ListView
4686
+ _ = PInvoke . SetWindowTheme (
4687
+ HWND ,
4688
+ $ "{ DarkModeIdentifier } _{ ExplorerThemeIdentifier } ",
4689
+ null ) ;
4665
4690
4666
4691
// Get the ListView's ColumnHeader handle:
4667
4692
HWND columnHeaderHandle = ( HWND ) PInvokeCore . SendMessage ( this , PInvoke . LVM_GETHEADER , ( WPARAM ) 0 , ( LPARAM ) 0 ) ;
4693
+
4694
+ // Apply dark mode theme to the ColumnHeader
4668
4695
PInvoke . SetWindowTheme ( columnHeaderHandle , $ "{ DarkModeIdentifier } _{ ItemsViewThemeIdentifier } ", null ) ;
4669
4696
}
4670
- #pragma warning restore WFO5001
4671
4697
}
4698
+ #pragma warning restore WFO5001
4672
4699
4673
4700
protected override void OnHandleDestroyed ( EventArgs e )
4674
4701
{
@@ -5622,68 +5649,86 @@ private void UpdateColumnWidths(ColumnHeaderAutoResizeStyle headerAutoResize)
5622
5649
}
5623
5650
}
5624
5651
5625
- protected void UpdateExtendedStyles ( )
5652
+ private uint BuildExStyleInternal ( )
5626
5653
{
5627
- if ( IsHandleCreated )
5654
+ if ( ! IsHandleCreated )
5628
5655
{
5629
- uint exStyle = 0 ;
5630
- uint exMask = PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_TWOCLICKACTIVATE |
5631
- PInvoke . LVS_EX_TRACKSELECT | PInvoke . LVS_EX_UNDERLINEHOT |
5632
- PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_HEADERDRAGDROP |
5633
- PInvoke . LVS_EX_CHECKBOXES | PInvoke . LVS_EX_FULLROWSELECT |
5634
- PInvoke . LVS_EX_GRIDLINES | PInvoke . LVS_EX_INFOTIP | PInvoke . LVS_EX_DOUBLEBUFFER ;
5656
+ return 0 ;
5657
+ }
5635
5658
5636
- switch ( _activation )
5637
- {
5638
- case ItemActivation . OneClick :
5639
- exStyle |= PInvoke . LVS_EX_ONECLICKACTIVATE ;
5640
- break ;
5641
- case ItemActivation . TwoClick :
5642
- exStyle |= PInvoke . LVS_EX_TWOCLICKACTIVATE ;
5643
- break ;
5644
- }
5659
+ uint exStyle = 0 ;
5645
5660
5646
- if ( AllowColumnReorder )
5647
- {
5648
- exStyle |= PInvoke . LVS_EX_HEADERDRAGDROP ;
5649
- }
5661
+ switch ( _activation )
5662
+ {
5663
+ case ItemActivation . OneClick :
5664
+ exStyle |= PInvoke . LVS_EX_ONECLICKACTIVATE ;
5665
+ break ;
5666
+ case ItemActivation . TwoClick :
5667
+ exStyle |= PInvoke . LVS_EX_TWOCLICKACTIVATE ;
5668
+ break ;
5669
+ }
5650
5670
5651
- if ( CheckBoxes )
5652
- {
5653
- exStyle |= PInvoke . LVS_EX_CHECKBOXES ;
5654
- }
5671
+ if ( AllowColumnReorder )
5672
+ {
5673
+ exStyle |= PInvoke . LVS_EX_HEADERDRAGDROP ;
5674
+ }
5655
5675
5656
- if ( DoubleBuffered )
5657
- {
5658
- exStyle |= PInvoke . LVS_EX_DOUBLEBUFFER ;
5659
- }
5676
+ if ( CheckBoxes )
5677
+ {
5678
+ exStyle |= PInvoke . LVS_EX_CHECKBOXES ;
5679
+ }
5660
5680
5661
- if ( FullRowSelect )
5662
- {
5663
- exStyle |= PInvoke . LVS_EX_FULLROWSELECT ;
5664
- }
5681
+ if ( DoubleBuffered )
5682
+ {
5683
+ exStyle |= PInvoke . LVS_EX_DOUBLEBUFFER ;
5684
+ }
5665
5685
5666
- if ( GridLines )
5667
- {
5668
- exStyle |= PInvoke . LVS_EX_GRIDLINES ;
5669
- }
5686
+ if ( FullRowSelect )
5687
+ {
5688
+ exStyle |= PInvoke . LVS_EX_FULLROWSELECT ;
5689
+ }
5670
5690
5671
- if ( HoverSelection )
5672
- {
5673
- exStyle |= PInvoke . LVS_EX_TRACKSELECT ;
5674
- }
5691
+ if ( GridLines )
5692
+ {
5693
+ exStyle |= PInvoke . LVS_EX_GRIDLINES ;
5694
+ }
5675
5695
5676
- if ( HotTracking )
5677
- {
5678
- exStyle |= PInvoke . LVS_EX_UNDERLINEHOT ;
5679
- }
5696
+ if ( HoverSelection )
5697
+ {
5698
+ exStyle |= PInvoke . LVS_EX_TRACKSELECT ;
5699
+ }
5680
5700
5681
- if ( ShowItemToolTips )
5682
- {
5683
- exStyle |= PInvoke . LVS_EX_INFOTIP ;
5684
- }
5701
+ if ( HotTracking )
5702
+ {
5703
+ exStyle |= PInvoke . LVS_EX_UNDERLINEHOT ;
5704
+ }
5705
+
5706
+ if ( ShowItemToolTips )
5707
+ {
5708
+ exStyle |= PInvoke . LVS_EX_INFOTIP ;
5709
+ }
5710
+
5711
+ return exStyle ;
5712
+ }
5713
+
5714
+ protected void UpdateExtendedStyles ( )
5715
+ {
5716
+ if ( IsHandleCreated )
5717
+ {
5718
+ uint exMask = PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_TWOCLICKACTIVATE |
5719
+ PInvoke . LVS_EX_TRACKSELECT | PInvoke . LVS_EX_UNDERLINEHOT |
5720
+ PInvoke . LVS_EX_ONECLICKACTIVATE | PInvoke . LVS_EX_HEADERDRAGDROP |
5721
+ PInvoke . LVS_EX_CHECKBOXES | PInvoke . LVS_EX_FULLROWSELECT |
5722
+ PInvoke . LVS_EX_GRIDLINES | PInvoke . LVS_EX_INFOTIP | PInvoke . LVS_EX_DOUBLEBUFFER ;
5723
+
5724
+ uint exStyle = BuildExStyleInternal ( ) ;
5725
+
5726
+ PInvokeCore . SendMessage (
5727
+ this ,
5728
+ PInvoke . LVM_SETEXTENDEDLISTVIEWSTYLE ,
5729
+ ( WPARAM ) exMask ,
5730
+ ( LPARAM ) exStyle ) ;
5685
5731
5686
- PInvokeCore . SendMessage ( this , PInvoke . LVM_SETEXTENDEDLISTVIEWSTYLE , ( WPARAM ) exMask , ( LPARAM ) exStyle ) ;
5687
5732
Invalidate ( ) ;
5688
5733
}
5689
5734
}
@@ -6405,6 +6450,7 @@ internal void RecreateHandleInternal()
6405
6450
}
6406
6451
6407
6452
RecreateHandle ( ) ;
6453
+ ApplyDarkModeOnDemand ( ) ;
6408
6454
}
6409
6455
6410
6456
private unsafe void WmReflectNotify ( ref Message m )
0 commit comments