c# - Position a button after the last listviewitem -


my listview bound observablecollection, there way position button after last listviewitem? have done define button in datatemplate below:

    <datatemplate x:key="testdatatemplate">     <grid>         <grid.columndefinitions>             <columndefinition width="auto"/>             <columndefinition width="auto"/>         </grid.columndefinitions>                         <textblock x:name="seletedfiltertext" text="{binding}" />             <button command="{binding datacontext.testcommand,elementname=testlistview}"                                     content="test"                                     visibility="{binding converter={staticresource testconverter}}"                 grid.column="1"/>             </grid>       </datatemplate> 

in viewmodel, define string variable store last item. itemsource(an observable) may add or remove item, every time set last of collection lastitem variable. in converter, compare binding content lastitem, if value true, display button, if false, hide it. converter never triggered. can help?

i suggest not have backup field in viewmodel keep track of lastitem in collection.

you can converter in place return true or false if passed listviewitem last item in listview or not.

in case want call converter whenever underlying observablecollection add/remove item in it, suggest pass count property converter converter gets fired whenever item added/removed collection.


converter code:

public class islastitemincontainerconverter : imultivalueconverter {     public object convert(object[] values, type targettype, object parameter,                           cultureinfo culture)     {         dependencyobject item = (dependencyobject)values[0];         itemscontrol ic = itemscontrol.itemscontrolfromitemcontainer(item);          if (ic != null)         {             return ic.itemcontainergenerator.indexfromcontainer(item)                       == ic.items.count - 1;         }         else             return false;     }      public object[] convertback(object value, type[] targettypes,                                 object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

xaml:

<button content="test">    <button.style>      <style targettype="button">        <setter property="visibility" value="collapsed"/>        <style.triggers>          <datatrigger value="true">            <datatrigger.binding>              <multibinding                   converter="{staticresource islastitemincontainerconverter}">                 <binding path="."                          relativesource="{relativesource mode=findancestor,                                             ancestortype=listviewitem}"/>                 <binding path="datacontext.sourcecollection.count"                          relativesource="{relativesource mode=findancestor,                                                      ancestortype=listview}"/>              </multibinding>            </datatrigger.binding>            <setter property="visibility" value="visible"/>          </datatrigger>        </style.triggers>      </style>    </button.style> </button> 

replace sourcecollection observablecollection name in datatrigger.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -