layout - WPF item panel that keeps aspect ratio -
i have itemscontrol may contain arbitrary number of items (unknown @ design time). each of these items represented infinitely-scalable image fixed aspect ratio (ie. image draw in whatever space given -- not dictate own size except aspect ratio must preserved). aspect ratio each item might differ same.
i want to:
- draw border around each image, ideally of uniform thickness regardless of image scaling.
- draw each image large possible within window, while maintaining order, aspect ratio, , margins external border.
- at least 2 of 4 sides of image must touch invisible boundaries of cell within. other 2 sides should centred if not touching. (assuming sort of uniform cell layout used.)
- not overlap or clip images.
- automatically re-layout containing window resized.
- waste minimum amount of non-image space.
- cope possible if aspect ratios of items differ. (but it's ok if increases wasted space of other items, long rescale fit result.)
the general consensus i've found seems to wrap each image in stretch.uniform viewbox, , put uniformgrid. i've tried approach doesn't appeal me because:
- given 2 items, uniformgrid wants create 2x2 grid layout when window shape make 2x1 or 1x2 grid more suitable, results in over-scaling , wasted space.
- if put border within viewbox scales border thickness. if put outside distorts aspect ratio.
is there better way this? (note "image" own custom-draw frameworkelement, can put custom measure/arrange code in here or in custom container panel if help.)
<uniformgrid> <rectangle fill="red" margin="4" width="500" height="281.25" /> <rectangle fill="blue" margin="4" width="500" height="281.25" /> </uniformgrid> here's simple example. put window, try resizing window. rectangles change size fit window (good), change shape/aspect (bad), , stop resizing once window sufficiently large (bad). leaves space entire 2x2 grid when window sized such 1x2 or 2x1 work better.
<uniformgrid> <viewbox stretch="uniform" margin="4"><rectangle fill="red" width="500" height="281.25" /></viewbox> <viewbox stretch="uniform" margin="4"><rectangle fill="blue" width="500" height="281.25" /></viewbox> </uniformgrid> this works marginally better in rectangles continue stretch when window gets large, , no longer distort shape, there's still needless second row when window wide or second column when window narrow. , prefer elements line top left (like wrappanel) rather centering, that's minor detail.
(and try adding border, both inside , outside of viewbox, , see mean there.)
actually wrappanel want, except auto-sizes items large when window gets smaller.
Comments
Post a Comment