-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
44 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 12 additions & 63 deletions
75
ModernWpf.Controls/Repeater/ItemsRepeater/ItemsRepeater.wpf.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,34 @@ | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace ModernWpf.Controls | ||
{ | ||
partial class ItemsRepeater | ||
{ | ||
internal bool AlwaysInvalidateMeasureOnChildDesiredSizeChanged { get; set; } | ||
|
||
// WPF-specific workaround to avoid freezing and improve performance | ||
protected override void OnChildDesiredSizeChanged(UIElement child) | ||
{ | ||
if (AlwaysInvalidateMeasureOnChildDesiredSizeChanged) | ||
var virtInfo = TryGetVirtualizationInfo(child); | ||
if (virtInfo != null && virtInfo.IsRealized) | ||
{ | ||
base.OnChildDesiredSizeChanged(child); | ||
return; | ||
} | ||
|
||
bool ignore = true; | ||
|
||
var last = m_layoutEvents.Last; | ||
if (last != null) | ||
{ | ||
if (last.Value == LayoutEvent.Measure) | ||
{ | ||
if (last.Previous?.Value != LayoutEvent.Measure) | ||
{ | ||
ignore = false; | ||
} | ||
} | ||
else if (last.Value == LayoutEvent.Arrange) | ||
var oldDesiredSize = virtInfo.DesiredSize; | ||
if (!oldDesiredSize.IsEmpty) | ||
{ | ||
var previous = last.Previous; | ||
if (previous == null || previous.Value == LayoutEvent.Measure) | ||
var newDesiredSize = child.DesiredSize; | ||
var renderSize = child.RenderSize; | ||
|
||
if (newDesiredSize.Height != oldDesiredSize.Height && renderSize.Height == oldDesiredSize.Height || | ||
newDesiredSize.Width != oldDesiredSize.Width && renderSize.Width == oldDesiredSize.Width) | ||
{ | ||
var virtInfo = GetVirtualizationInfo(child); | ||
if (virtInfo.IsPinned) | ||
{ | ||
ignore = false; | ||
} | ||
base.OnChildDesiredSizeChanged(child); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
ignore = false; | ||
} | ||
|
||
if (!ignore) | ||
{ | ||
OnLayoutEvent(LayoutEvent.ChildDesiredSizeChanged); | ||
base.OnChildDesiredSizeChanged(child); | ||
} | ||
} | ||
|
||
protected override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent) | ||
{ | ||
return new RepeaterUIElementCollection(this, logicalParent); | ||
} | ||
|
||
private void OnLayoutEvent(LayoutEvent e) | ||
{ | ||
if (AlwaysInvalidateMeasureOnChildDesiredSizeChanged) | ||
{ | ||
return; | ||
} | ||
|
||
if (m_layoutEvents.Count >= 2) | ||
{ | ||
m_layoutEvents.RemoveFirst(); | ||
} | ||
|
||
m_layoutEvents.AddLast(e); | ||
} | ||
|
||
private enum LayoutEvent | ||
{ | ||
Measure, | ||
Arrange, | ||
ChildDesiredSizeChanged | ||
} | ||
|
||
private readonly LinkedList<LayoutEvent> m_layoutEvents = new LinkedList<LayoutEvent>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters