xaml - WPF - Groupbox header alignment -
in wpf app, want achieve groupbox:
goal http://imagizer.imageshack.us/a/img829/189/15iy.png
the goal creating template header, display in left (checkbox + text), , in right side (button).
unfortunately, is:
what http://imageshack.com/a/img513/706/fiaq.png
i not programmatically, in xaml (as cleaner possible). mean, using grids, columndefinitions, etc... not dealing margins crash when resizing window.
the xaml i'm using (grid 3 columns):
<groupbox margin="5"> <groupbox.header> <grid> <grid.columndefinitions> <columndefinition width="15"></columndefinition> <columndefinition width="100*"></columndefinition> <columndefinition width="auto"></columndefinition> </grid.columndefinitions> <checkbox grid.column="0"></checkbox> <textblock grid.column="1" margin="5,0,5,0" text="this groupbox"></textblock> <button content="click" fontsize="8" background="yellow" grid.column="2" height="16" width="54"></button> </grid> </groupbox.header> </groupbox>
what think?
by default header left align groupbox header. in case want few parts left aligned , few right need override controltemplate
of groupbox header defined here , here.
however, can force grid stretch horizontally
button can placed in right. can see in snapshot, border line gets hide header content might this:
relevant code achieve be:
xaml
<groupbox margin="5" x:name="groupbox" xmlns:local="clr-namespace:namespaceofconverter"> <groupbox.resources> <local:subtractionconverter x:key="subtractionconverter"/> </groupbox.resources> <groupbox.header> <grid width="{binding actualwidth, elementname=groupbox, converter={staticresource subtractionconverter}}"> <grid.columndefinitions> <columndefinition width="15"></columndefinition> <columndefinition width="auto"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <checkbox grid.column="0"/> <textblock grid.column="1" margin="5,0,5,0" text="this groupbox"/> <button content="click" fontsize="8" background="yellow" horizontalalignment="right" grid.column="2" height="16" width="54"/> </grid> </groupbox.header> </groupbox>
converter
public class subtractionconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { return (double)value - 25.0; } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { return binding.donothing; } }
Comments
Post a Comment