.net - WPF: How to implement a panel with adjustable font size? -
i have panel several textblock
s. want modify panel such font size of each textblock changes depending on size of panel.
the size of panel can change when user changes size of window (e. g. maximizes or restores it).
i tried using viewbox
:
<viewbox stretch="fill"> <grid width="{binding relativesource={relativesource findancestor, ancestortype={x:type viewbox}}, path=width}"> <grid.rowdefinitions> <rowdefinition height="auto"/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> </grid.columndefinitions> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> <textblock horizontalalignment="stretch" verticalalignment="stretch" /> </grid> </viewbox>
but doesn't work because
- font size doesn't bigger, when size of
viewbox
increases and - it doesn't smaller, when size of
viewbox
decreases.
how can implement scaling of these text blocks (so fill entire available area, , adapt font sizes) ?
you have height width auto , not placing textblocks in grid
<grid> <viewbox stretch="fill"> <grid width="{binding relativesource={relativesource findancestor, ancestortype={x:type viewbox}}, path=width}"> <grid.rowdefinitions> <rowdefinition height="*"/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> </grid.columndefinitions> <textblock grid.column="0" text="textblock1" horizontalalignment="stretch" verticalalignment="stretch" /> <textblock grid.column="1" text="textblock2" horizontalalignment="stretch" verticalalignment="stretch" /> <textblock grid.column="2" text="textblock3" horizontalalignment="stretch" verticalalignment="stretch" /> </grid> </viewbox> </grid>
Comments
Post a Comment