c# - WPF Tab Control force Scrollviewer to display newly added item -


i using wpf mvvm c#. have scrollviewer in usercontrol , need following functionality haven't been able work out how basically:

when item gets added content of scrollviewer; if item added not visible scrollviewer scroll down can view newly added item in listview. have been able bind selected item not sure how make scroll it.

that's there i'm not sure how this. if there's comments or questions i'll try suitably amend post, i've included .xaml below

thanks

     <scrollviewer  background="pink" horizontalalignment="left" height="173" x:name="scrollviewer1" width="560" verticalscrollbarvisibility="auto" horizontalscrollbarvisibility="hidden">                                  <grid name="gridvaluesandpartss" verticalalignment="top"  height="165">                                     <grid.columndefinitions>                                         <columndefinition width="370" />                                         <columndefinition width="204" />                                      </grid.columndefinitions>                                     <listview  selecteditem="{binding selectedbetmyvalue, mode=twoway}" itemssource="{binding values}"  name="betvalueslistview" height="auto"  margin="0,0,0,0"  myvaluemode="single" horizontalalignment="stretch" verticalalignment="stretch">                                        <listview.view>                                             <gridview>                                                 <gridviewcolumn  header="price      "    width="95">                                                     <gridviewcolumn.celltemplate>                                                         <datatemplate>                                                             <stackpanel orientation="horizontal"  margin="-7,0,0,0" minwidth="95" width="auto">                                                                                                                                    <textblock text="{binding path=pricetypecode}" foreground="black" fontsize="10" tooltip="price type code" />                                                                 <textblock text=":" foreground="black" fontsize="10" tooltip="price type code" />                                                                 <textblock text="{binding path=pricetaken,converter={staticresource myvaluepricedisplayconverter}}" foreground="red" fontsize="10" tooltip="price taken"  />                                                                 <textblock text="." fontsize="4" />                                                                 <textblock text="{binding path=pricecurrent,converter={staticresource myvaluepricedisplayconverter}}" foreground="black" fontsize="10" tooltip="price @ scan time"  />                                                                 <textblock text="." fontsize="4" />                                                                                                                                        <textblock text="{binding path=pricesp,converter={staticresource myvaluepricedisplayconverter}}" foreground="green" fontsize="10" tooltip="price sp"   />                                                             </stackpanel>                                                            </datatemplate>                                                     </gridviewcolumn.celltemplate>                                                 </gridviewcolumn>                                             </gridview>                                         </listview.view>                                     </listview>                                  </grid>                              </scrollviewer> 

i try use here code behind little bit.

  1. give scrollviewer name (like 'x:name="myscrolly"').
  2. listen 'selectionchanged'-event of listview.
  3. in event handler of selection changed event (code behind) call:

    myscrolly.scrolltobottom();

i think new item @ bottom. if not try method: 'scrolltoverticaloffset()'.


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 -