wpf - Make ObservableCollection item invisible -


this model:

observablecollection<student> studentslist; class student {     static observablecollection<student> students;     string sname;     string fname; } 

and have simple combobox:

<combobox     x:name="cbstudents"      itemssource="{binding studentslist}"> 

i case want hide combobox item/items, possible without using function remove students observablecollection ?

edit:

after try mm8 solution seems combo box style cause error style:

<!-- region combobox style -->         <solidcolorbrush x:key="comboboxnormalborderbrush" color="transparent" />         <solidcolorbrush x:key="comboboxnormalbackgroundbrush" color="#ff103766" />         <solidcolorbrush x:key="comboboxdisabledforegroundbrush" color="#888" />         <solidcolorbrush x:key="comboboxdisabledbackgroundbrush" color="#ff7aa0cd" />         <solidcolorbrush x:key="comboboxdisabledborderbrush" color="#ff7aa0cd" />          <style targettype="{x:type comboboxitem}">             <setter property="snapstodevicepixels" value="true" />             <setter property="horizontalalignment" value="stretch" />             <setter property="verticalalignment" value="stretch" />             <setter property="overridesdefaultstyle" value="true"/>             <setter property="template">                 <setter.value>                     <controltemplate targettype="comboboxitem">                         <border                             name="border"                             padding="5"                             margin="0"                             borderthickness="0"                             cornerradius="0"                             background="transparent"                             borderbrush="transparent" >                              <textblock textalignment="left">                                 <contentpresenter />                             </textblock>                         </border>                         <controltemplate.triggers>                             <multitrigger>                                 <multitrigger.conditions>                                     <condition property="ismouseover" value="true"/>                                     <condition property="isselected" value="false"/>                                     <condition property="ishighlighted" value="true"/>                                 </multitrigger.conditions>                                 <setter property="foreground" value="white"/>                                 <setter targetname="border" property="borderbrush" value="#ff103766"/>                                 <setter targetname="border" property="background" value="#ff103766"/>                             </multitrigger>                              <multitrigger>                                 <multitrigger.conditions>                                     <condition property="ismouseover" value="false"/>                                     <condition property="isselected" value="true"/>                                 </multitrigger.conditions>                                 <setter property="foreground" value="white"/>                                 <setter targetname="border" property="borderbrush" value="#ff103766"/>                                 <setter targetname="border" property="background" value="#ff103766"/>                             </multitrigger>                              <multitrigger>                                 <multitrigger.conditions>                                     <condition property="ismouseover" value="true"/>                                     <condition property="isselected" value="true"/>                                 </multitrigger.conditions>                                 <setter property="foreground" value="white"/>                                 <setter targetname="border" property="borderbrush" value="#ff103766"/>                                 <setter targetname="border" property="background" value="#ff103766"/>                             </multitrigger>                              <multitrigger>                                 <multitrigger.conditions>                                     <condition property="ismouseover" value="false"/>                                     <condition property="isselected" value="false"/>                                 </multitrigger.conditions>                                 <setter property="foreground" value="#ff103766"/>                                 <setter targetname="border" property="borderbrush" value="white"/>                                 <setter targetname="border" property="background" value="white"/>                             </multitrigger>                          </controltemplate.triggers>                     </controltemplate>                 </setter.value>             </setter>         </style>          <controltemplate targettype="togglebutton" x:key="comboboxtogglebuttontemplate">             <grid>                 <grid.columndefinitions>                     <columndefinition />                     <columndefinition width="20" />                 </grid.columndefinitions>                 <border                      grid.columnspan="2"                     name="border"                     borderbrush="{staticresource comboboxnormalborderbrush}"                      cornerradius="0"                     borderthickness="1, 1, 1, 1"                      background="{staticresource comboboxnormalbackgroundbrush}" />                 <border                      grid.column="1"                     margin="1, 1, 1, 1"                     borderbrush="#444"                     name="buttonborder"                     cornerradius="0, 0, 0, 0"                     borderthickness="0, 0, 0, 0"                      background="{staticresource comboboxnormalbackgroundbrush}" />                 <path                     name="arrow"                     grid.column="1"                      data="m 0 0 l 8 12 l 16 0 z"                     horizontalalignment="center"                     fill="#444"                     verticalalignment="center"                      margin="-10,0,0,0"/>             </grid>             <controltemplate.triggers>                 <trigger property="uielement.ismouseover" value="true">                     <setter property="panel.background" targetname="buttonborder" value="transparent"/>                     <setter property="shape.fill" targetname="arrow" value="white"/>                     <setter property="panel.background" targetname="border" value="#ff7aa0cd"/>                 </trigger>                 <trigger property="uielement.ismouseover" value="false">                     <setter property="shape.fill" targetname="arrow" value="transparent"/>                 </trigger>                 <trigger property="togglebutton.ischecked" value="true">                     <setter property="panel.background" targetname="buttonborder" value="transparent"/>                     <setter property="shape.fill" targetname="arrow" value="white"/>                 </trigger>                 <trigger property="uielement.isenabled" value="false">                     <setter property="panel.background" targetname="border" value="{staticresource comboboxdisabledbackgroundbrush}"/>                     <setter property="panel.background" targetname="buttonborder" value="{staticresource comboboxdisabledbackgroundbrush}"/>                     <setter property="border.borderbrush" targetname="buttonborder" value="{staticresource comboboxdisabledborderbrush}"/>                     <setter property="textelement.foreground" value="{staticresource comboboxdisabledforegroundbrush}"/>                     <setter property="shape.fill" targetname="arrow" value="transparent"/>                 </trigger>             </controltemplate.triggers>         </controltemplate>          <style x:key="comboboxflatstyle"  targettype="{x:type combobox}">             <setter property="uielement.snapstodevicepixels" value="true"/>             <setter property="frameworkelement.overridesdefaultstyle" value="true"/>             <setter property="scrollviewer.horizontalscrollbarvisibility" value="auto"/>             <setter property="scrollviewer.verticalscrollbarvisibility" value="auto"/>             <setter property="scrollviewer.cancontentscroll" value="true"/>             <setter property="textelement.foreground" value="gainsboro"/>             <setter property="frameworkelement.focusvisualstyle" value="{x:null}"/>             <setter property="control.template">                 <setter.value>                     <controltemplate targettype="combobox">                         <grid>                             <togglebutton                                  name="togglebutton"                                 grid.column="2"                                 clickmode="press"                                 focusable="false"                                 ischecked="{binding path=isdropdownopen, relativesource={relativesource templatedparent}, mode=twoway}"                                 template="{staticresource comboboxtogglebuttontemplate}"/>                             <contentpresenter                                  name="contentsite"                                 margin="5, 4, 23, 3"                                 ishittestvisible="false"                                 horizontalalignment="left"                                 verticalalignment="center"                                                               content="{templatebinding combobox.selectionboxitem}"                                  contenttemplate="{templatebinding combobox.selectionboxitemtemplate}"                                 contenttemplateselector="{templatebinding itemtemplateselector}"/>                             <textbox                                 name="part_editabletextbox"                                 margin="3, 3, 23, 3"                                                      isreadonly="{templatebinding isreadonly}"                                 visibility="hidden"                                 background="transparent"                                 horizontalalignment="left"                                 verticalalignment="center"                                 focusable="true" >                                 <textbox.template>                                     <controltemplate targettype="textbox" >                                         <border name="part_contenthost" focusable="false" />                                     </controltemplate>                                 </textbox.template>                             </textbox>                             <popup                                  name="popup"                                 placement="bottom"                                 focusable="false"                                 allowstransparency="true"                                 isopen="{templatebinding combobox.isdropdownopen}"                                 popupanimation="fade">                                 <grid                                      name="dropdown"                                     snapstodevicepixels="true"                                     minwidth="{templatebinding frameworkelement.actualwidth}"                                     maxheight="{templatebinding combobox.maxdropdownheight}">                                     <border                                         name="dropdownborder"                                         background="gainsboro"                                         margin="0, 0, 0, 0"                                         cornerradius="0"                                                                                 borderbrush="#ff103766"                                         borderthickness="1" />                                     <scrollviewer margin="4" snapstodevicepixels="true">                                         <itemspresenter keyboardnavigation.directionalnavigation="contained" />                                     </scrollviewer>                                 </grid>                             </popup>                             <!-- popup showing items -->                         </grid>                         <controltemplate.triggers>                             <trigger property="uielement.ismouseover" value="true">                                 <setter property="textelement.foreground" value="white"/>                             </trigger>                             <trigger property="uielement.ismouseover" value="false">                                 <setter property="textelement.foreground" value="gainsboro"/>                             </trigger>                             <trigger property="itemscontrol.hasitems" value="false">                                 <setter property="frameworkelement.minheight" targetname="dropdownborder" value="95"/>                             </trigger>                             <trigger property="uielement.isenabled" value="false">                                 <setter property="textelement.foreground" value="gainsboro"/>                             </trigger>                             <trigger property="itemscontrol.isgrouping" value="true">                                 <setter property="scrollviewer.cancontentscroll" value="false"/>                             </trigger>                             <trigger property="combobox.iseditable" value="true">                                 <setter property="keyboardnavigation.istabstop" value="false"/>                                 <setter property="uielement.visibility" targetname="part_editabletextbox" value="visible"/>                                 <setter property="uielement.visibility" targetname="contentsite" value="hidden"/>                             </trigger>                         </controltemplate.triggers>                     </controltemplate>                 </setter.value>             </setter>         </style>         <!-- endregion of flat combobox --> 

you use itemcontainerstyle datatrigger example hide student particular name, e.g.:

<combobox             x:name="cbstudents"              itemssource="{binding studentslist}">     <combobox.itemcontainerstyle>         <style targettype="comboboxitem">             <style.triggers>                 <datatrigger binding="{binding sname}" value="somename">                     <setter property="visibility" value="collapsed" />                 </datatrigger>             </style.triggers>         </style>     </combobox.itemcontainerstyle> </combobox> 

edit: (see comments below) "comboboxflatstyle" combobox style. itemcontainerstyle should based on implicit comboboxitem style:

<combobox style="{staticresource comboboxflatstyle}" ...>     <combobox.itemcontainerstyle>         <style targettype="comboboxitem" basedon="{staticresource {x:type comboboxitem}}">             ...         </style>     </combobox.itemcontainerstyle> </combobox> 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -