Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had to calculate the desired height by getting the ScrollViewer's content desired height and adding the ScrollBar height if visible.</p> <p>This still feels slightly awkward to me, so if you have a better solution, I'll gladly change the accepted answer.</p> <pre><code>public class HeightChangedBehavior : Behavior&lt;ScrollViewer&gt; { public ICommand HeightChangedCommand { get { return (ICommand)GetValue(HeightChangedCommandProperty); } set { SetValue(HeightChangedCommandProperty, value); } } public static readonly DependencyProperty HeightChangedCommandProperty = DependencyProperty.Register("HeightChangedCommand", typeof(ICommand), typeof(HeightChangedBehavior), new PropertyMetadata(null)); protected override void OnAttached() { this.AssociatedObject.ScrollChanged += AssociatedObject_ScrollChanged; base.OnAttached(); } /// &lt;summary&gt; /// Calculates the desired height for the scrollviewer, as the sum of its content /// desired height and, if visible, the horizontal scrollbar height. /// &lt;/summary&gt; void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArgs e) { ScrollViewer sv = (ScrollViewer)sender; // get content height double height = ((FrameworkElement)sv.Content).DesiredSize.Height; if (sv.ComputedHorizontalScrollBarVisibility == Visibility.Visible) { // add scrollbar height height += (double)sv.FindResource(SystemParameters.HorizontalScrollBarHeightKey); // template of scrollbar should use this key } int intHeight = (int)Math.Ceiling(height); // whole pixels // execute the command ICommand cmd = this.HeightChangedCommand; if (cmd != null &amp;&amp; intHeight != sv.ActualHeight) cmd.Execute(intHeight); } } </code></pre>
 

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