c# - The logic behind WPF's GetLayoutClip() -


as understand it, getlayoutclip (as called static class layoutinformation) produce geometry outside of layout in wpf clip uielement (except, of course, if uielement 1 in clipping off default - such canvas). understand logic better, i've tried experiment using grid i'm getting results find bit strange. i've used following code experiment.

xaml:

<window x:class="testsolution.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" width="216" height="139" loaded="window_loaded"> </window> 

and in code-behind:

private grid panel;      public mainwindow()     {         initializecomponent();         panel = new grid();         panel.margin = new thickness(0,70,10,0);         panel.width = 150;         panel.height = 100;         panel.cliptobounds = true;         content = panel;     }      private void window_loaded(object sender, routedeventargs e)     {          debug.writeline(panel.desiredsize);         debug.writeline(panel.rendersize);         debug.writeline(layoutinformation.getlayoutclip(panel).bounds);     } 

notice i'm forcing cliptobounds. unsurprisingly, getlayoutclip returns rectangle = (0,0,150,30), makes complete sense; geometry begins @ origin of gridpanel , clips below window , outside width of grid (including whatever overflow margin on right).

however, if turn off cliptobounds, rectangle becomes (-20,0,190,30). ok, -20 sort of makes sense me; relative origin of grid gets edge of window on left hand side. 0 makes sense, that's 70 top , grid begins in y-direction. why 190 width though? grid terminates @ 170 , @ 180 including margin on right. there's nothing naturally ends @ 190. why 190?

when panel.cliptobounds = true clipped area restricted bounds of grid. however, when set 'false', possible content appear left or right side of panel negative margin. whole width of window taken clip rectangle. since grid placed in middle of window , has -20 offset left edge, width of rectangle is:

width = 216 - 20 - 3 - 3 = 190. 

where 3 size of window border.


Comments