WPF get ListView height in C# when Window Size is changed -
i have following question:
have layout grid , listviews.
these listviews contain 5 items.
these items should fill complete height of listview.
thought height of listview devide 5 , set height of each row result.
listview.height property returns strange values.
listen window sizechanged event.
hope can tell me how it, or if there better alternative.
<window x:class="kalenderdesingtest.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="kalender" height="600" width="800" sizechanged="window_sizechanged"> <grid> <grid.resources> <style targettype="{x:type listviewitem}"> <style.setters> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listviewitem}"> <border borderbrush="#5076a7" borderthickness="1" cornerradius="4"> <border.background> <lineargradientbrush startpoint="0,0" endpoint="0,1"> <gradientstop color="#ffffff" offset="0.0"/> <gradientstop color="#c0d3ea" offset="1.0"/> </lineargradientbrush> </border.background> <stackpanel textelement.fontfamily="segoe ui" textelement.fontsize="12"> <textblock fontweight="bold" padding="3,0,0,0" text="{binding path=name}"/> <textblock padding="3,0,0,0" text="{binding path=age}"/> </stackpanel> </border> </controltemplate> </setter.value> </setter> </style.setters> </style> </grid.resources> <grid.columndefinitions> <columndefinition width="50"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="50"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <button grid.column="0" grid.row="0" grid.rowspan="3" x:name="neuertermin">neuer termin</button> <button grid.column="2" grid.row="0" x:name="back">zurück</button> <combobox grid.column="3" grid.row="0" x:name="month"></combobox> <button grid.column="4" grid.row="0" x:name="forward">vor</button> <textblock grid.column="1" grid.row="1" text="montag" horizontalalignment="center"/> <textblock grid.column="2" grid.row="1" text="dienstag" horizontalalignment="center"/> <textblock grid.column="3" grid.row="1" text="mittwoch" horizontalalignment="center"/> <textblock grid.column="4" grid.row="1" text="donnerstag" horizontalalignment="center"/> <textblock grid.column="5" grid.row="1" text="freitag" horizontalalignment="center"/> <stackpanel orientation="horizontal" grid.column="1" grid.row="2" verticalalignment="stretch"> <checkbox x:name="mov" verticalalignment="center" margin="0,0,5,0">v</checkbox> <checkbox x:name="mon" verticalalignment="center" margin="0,0,5,0">n</checkbox> <checkbox x:name="mot" verticalalignment="center">t</checkbox> </stackpanel> <stackpanel orientation="horizontal" grid.column="2" grid.row="2" verticalalignment="stretch"> <checkbox x:name="div" verticalalignment="center" margin="0,0,5,0">v</checkbox> <checkbox x:name="din" verticalalignment="center" margin="0,0,5,0">n</checkbox> <checkbox x:name="dit" verticalalignment="center">t</checkbox> </stackpanel> <stackpanel orientation="horizontal" grid.column="3" grid.row="2" verticalalignment="stretch"> <checkbox x:name="miv" verticalalignment="center" margin="0,0,5,0">v</checkbox> <checkbox x:name="min" verticalalignment="center" margin="0,0,5,0">n</checkbox> <checkbox x:name="mit" verticalalignment="center">t</checkbox> </stackpanel> <stackpanel orientation="horizontal" grid.column="4" grid.row="2" verticalalignment="stretch"> <checkbox x:name="dov" verticalalignment="center" margin="0,0,5,0">v</checkbox> <checkbox x:name="don" verticalalignment="center" margin="0,0,5,0">n</checkbox> <checkbox x:name="dot" verticalalignment="center">t</checkbox> </stackpanel> <stackpanel orientation="horizontal" grid.column="5" grid.row="2" verticalalignment="stretch"> <checkbox x:name="frv" verticalalignment="center" margin="0,0,5,0">v</checkbox> <checkbox x:name="frn" verticalalignment="center" margin="0,0,5,0">n</checkbox> <checkbox x:name="frt" verticalalignment="center">t</checkbox> </stackpanel> <listview grid.column="1" grid.row="3" x:name="lvmov"></listview> <listview grid.column="1" grid.row="4" x:name="lvmon"></listview> <listview grid.column="2" grid.row="3" x:name="lvdiv"></listview> <listview grid.column="2" grid.row="4" x:name="lvdin"></listview> <listview grid.column="3" grid.row="3" x:name="lvmiv"></listview> <listview grid.column="3" grid.row="4" x:name="lvmin"></listview> <listview grid.column="4" grid.row="3" x:name="lvdov"></listview> <listview grid.column="4" grid.row="4" x:name="lvdon"></listview> <listview grid.column="5" grid.row="3" x:name="lvfrv"></listview> <listview grid.column="5" grid.row="4" x:name="lvfrn"></listview> </grid> </window>
this code behind:
private void window_sizechanged(object sender, sizechangedeventargs e) { int wheight = (int)lvmon.height; }
i this:
int wheight = (int)lvmon.actualheight;
Comments
Post a Comment