First had the problem with collapse of Expander not giving back space.
Based on the borders it appears to be the ListView is not shrinking rather than the Expander not s
It took a good bit of playing with your example, but I eventually realised what the root cause of the behaviour was, and what to go looking for.
I think you're experiencing an issue caused by your CheckBox
gaining focus when clicked, and raising a RequestBringIntoView
event, which will essentially cause the ScrollViewer
to kick the control containing your CheckBox
into the "correct" place. The mechanics are explained in this answer: Stop WPF ScrollViewer automatically scrolling to perceived content.
If that scroll happens whilst you're clicking on a CheckBox
, it will move out from under your cursor before you can unclick the mouse (you can demonstrate that by holding the mouse down when the problem occurs, and subsequently moving your mouse over the CheckBox
in question, and releasing it).
You could create a simple event handler for the RequestBringIntoView event and use it with the CheckBox
within your DataTemplate
, and suppress the event using the Handled
property, so it isn't propagated any further (the below worked for me).
XAML:
C#:
private void RequestBringIntoViewSuppressor(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
Your CheckBox
would now no longer correctly bring itself into view if it was slightly off the screen, but it wouldn't jump unexpectedly, and you could customise the handler further if required.