c# - Display certain contents depending on width of grid -
lets have 2 x 2 grid. contain contents of different importance.
cells (0,0) , (0,1) have important info. cells (1,0) , (1,1) have less important info.
when resize window, dimensions of grids change well. how not show non-important cells when grids beyond threshold width.
i have considered kind of value converter binds visibility min-width, there less hackish way this?
there may more elegant way this, following works.
it uses trigger set maxwidth property of right column's columndefinition 0 when window width falls below threshold.
xaml:
<window x:class="misc.window1" x:name="window1name" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="window1" height="300" width="300" sizechanged="window1_sizechanged"> <grid textblock.fontsize="40"> <grid.rowdefinitions> <rowdefinition/> <rowdefinition/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition/> <columndefinition x:name="rightcolumn"> <columndefinition.style> <style> <style.triggers> <datatrigger binding="{binding elementname=window1name, path=hiderightcolumn}" value="true"> <setter property="columndefinition.maxwidth" value="0"/> </datatrigger> </style.triggers> </style> </columndefinition.style> </columndefinition> </grid.columndefinitions> <textblock horizontalalignment="center" verticalalignment="center">0,0</textblock> <textblock grid.row="1" horizontalalignment="center" verticalalignment="center">0,1</textblock> <textblock grid.column="1" horizontalalignment="center" verticalalignment="center">1,0</textblock> <textblock grid.row="1" grid.column="1" horizontalalignment="center" verticalalignment="center">1,1</textblock> </grid> </window>
code behind:
public partial class window1 : window, inotifypropertychanged { public window1() { initializecomponent(); } public bool hiderightcolumn { { return this.width < 200; } } private void window1_sizechanged(object sender, sizechangedeventargs e) { if (propertychanged != null) propertychanged(this, new propertychangedeventargs("hiderightcolumn")); } #region inotifypropertychanged members public event propertychangedeventhandler propertychanged; #endregion }
Comments
Post a Comment