title: Get visible size of control in WPF
body: <p>I have a control that doesn't displayed fully (by decreasing of window size).
  But ActualWidth and RenderSize/DesiredSize of this control still show the total size of it.
  I wrote the next code, but it ignores the scrollbar width of window and looks ugly.
  Maybe there is a way to get a visible size of control with more elegant manner?</p>
  
  <pre><code>    private static double GetVisibleWidth(UIElement element, FrameworkElement container)
      {
          var visibleBounds =
              element.TransformToAncestor(container)
                  .TransformBounds(new Rect(new Point(0, 0), element.RenderSize));
  
          double visibleWidth = element.RenderSize.Width;
          if (container != null)
          {
              visibleWidth = Math.Min(container.ActualWidth - visibleBounds.X, visibleWidth);
          }
  
          return visibleWidth;
      }
  </code></pre>
  
  <p><img src="https://i.imgur.com/De0sDaI.png" alt="What size i am speaking about"></p>