Hiding list view items in listview wpf C# doesn't work -


i have following listview contains following xaml definition:

<listview height="307" width="991" name="orderlistview" itemssource="{ binding orders }">             <listview.itemcontainerstyle>                 <style targettype="listviewitem">                     <setter property="horizontalcontentalignment" value="center" />                     <style.triggers>                         <datatrigger binding="{binding path=isvisible}" value="false">                             <setter property="visibility" value="collapsed"></setter>                         </datatrigger>                     </style.triggers>                 </style>             </listview.itemcontainerstyle>             <listview.view>                 <gridview>                     <gridviewcolumn header="a header" displaymemberbinding="{binding path=storenumber}"></gridviewcolumn>                     ...                 </gridview>             </listview.view>         </listview> 

and model linked data context:

public sealed class ddmodel : inotifypropertychanged {    public observablecollection<order> orders    {             get;             set;    }     public event propertychangedeventhandler propertychanged; } 

and order has boolean property isvisible (see trigger style)

i create event text box @ keyup:

private void ordersearch_keyup(object sender, keyeventargs e) {     _backup = this.datacontext ddmodel;      string keyword = this.ordersearch.text;      var query = _backup.orders.tolist();      // make them visible     query.foreach(p => p.isvisible = true);      if (!string.isnullorwhitespace(keyword))     {         //then hide items doesn't match keyword         query.where(p => !p.ordernumber.tostring().startswith(keyword)).tolist().foreach(p => p.isvisible = false);     } } 

the listview not refreshed, trigger doesn't work , items not hidden.

but _backup contains few items isvisible set false;

where mistake ?

ps: orders not null or empty, loaded database when window initialised. listview not empty, contains few records (rows).

first of all, implement interface inotifypropertychanged (or base class implements interface) class order. setup properties correctly using onpropertychanged function provided interface. required since observablecollection orders not notified when instance of item in list changes.

this might follows:

class order : inotifypropertychanged {     // boilerplate code..      private bool _visible ;      public bool visible     {         { return _visible; }         set         {             if (_visible == value) return;             _visible = value;             onpropertychanged(() => _visible);         }     } } 

additionally should implement same functionality observablecollection orders.

your triggerevent should fired when visible property changes.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -