Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Grabacr07
Created October 31, 2014 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grabacr07/5510e17187ae2bf9e9ea to your computer and use it in GitHub Desktop.
Save Grabacr07/5510e17187ae2bf9e9ea to your computer and use it in GitHub Desktop.
Viewbox 内の要素が実際に描画されているサイズを計算するやつ (WPF)。Viewbox 内の要素 (real size を知りたいやつ) から Viewbox 外の要素 (このコードでは Window) にアクセスできれば、その座標系に変換してほげもげっと。たぶん。
/// <summary>
/// Viewbox 内に配置された要素について、実際に描画されているサイズを計算します。
/// </summary>
public static Size GetRealSize(FrameworkElement target)
{
var min = target.TranslatePoint(new Point(0, 0), Window.GetWindow(target));
var max = target.TranslatePoint(new Point(target.ActualWidth, target.ActualHeight), Window.GetWindow(target));
return (Size)(max - min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment