wpf - How do I create a button that has a uniform width and height? -
i create button size of it's largest edge.
the reason want button small information circle embedded inside datagrid
column.
currently have:
<datagridtemplatecolumn> <datagridtemplatecolumn.celltemplate> <datatemplate> <button content="i" padding="2" margin="0" verticalalignment="center" horizontalalignment="center" width="{binding source=self, path=height}"> <button.template> <controltemplate targettype="{x:type button}"> <grid> <ellipse fill="#fff4f4f5" stroke="#ff6695eb"/> <contentpresenter margin="0" recognizesaccesskey="false" snapstodevicepixels="true" verticalalignment="center" horizontalalignment="center" /> </grid> </controltemplate> </button.template> </button> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn>
create class derived button , override measuring, e.g.
public class squarebutton : button { protected override size measureoverride(size constraint) { size size = base.measureoverride(constraint); size.height = size.width = math.max(size.height, size.width); return size; } }
you can use this:
<local:squarebutton content="i" padding="2" margin="0" verticalalignment="center" horizontalalignment="center"> <local:squarebutton.template> <controltemplate targettype="{x:type button}"> <grid> <ellipse fill="#fff4f4f5" stroke="#ff6695eb"/> <contentpresenter margin="0" recognizesaccesskey="false" snapstodevicepixels="true" verticalalignment="center" horizontalalignment="center" /> </grid> </controltemplate> </local:squarebutton.template> </local:squarebutton>
Comments
Post a Comment