wpf - Move scrollbar in listbox programmatically exactly after window was loaded -


i have issue , i'll appreciate on it!

i have window dynamic count of listboxes. mvvm used. listbox , it's functionality usercontrol viewmodel created. when window creating, create specific count of usercontrols in constructor of window. , problem. listbox has it's maxwidth=350. , each listboxitem styled buttons in end. when names short - ok , user can see buttons in listbox after window loaded. if names long, listbox creates horizontal scrollbar because of maxwidth=350 (expected behavior.) once form loaded, seems buttons not created in listboxes (see image2:)image2: scrollbar appeared , buttons not visible question is: how can programmatically move scrollbar before window shown? image 3 shows need, , image 2 shows current view of listbox. needed result after loading window know how move scrollbar end?

thank you, @yog, tip focus(). indeed didn't realize focus method can move scrollbar! , remembered method, had used in c#, found method in site: how can find wpf controls name or type? rewrote method vb.net extension method, called on listbox, found stackpanel buttons , focus() stackpanel! important: if wants figure out problem focus() method, make sure specific xaml element has set focusable=true

here method on vb.net:

public function findchild(of t dependencyobject)(parent dependencyobject, childname string) t         if parent nothing return nothing          dim foundchild t = nothing         dim childrencount integer = visualtreehelper.getchildrencount(parent)          = 0 childrencount             dim child dependencyobject             try                 child = visualtreehelper.getchild(parent, i)             catch ex exception                 continue             end try              'if child not of request child type child             dim childtype t = trycast(child, t)             if childtype nothing                 'recursively drill down tree                 foundchild = child.findchild(of t)(childname)                 'if child found, break not overwrite found child.                 if foundchild isnot nothing exit             else                 if not string.isnullorempty(childname)                     dim frameworkelement = trycast(child, frameworkelement)                     'if child's name set search                     if frameworkelement isnot nothing andalso frameworkelement.name = childname                         'if child's name of request name                         foundchild = trycast(child, t)                         exit                     end if                 else                     'child element found.                     foundchild = trycast(child, t)                     exit                 end if             end if         next         return foundchild     end function 

visualtreehelper.getchild method threw exception, didn't figure out why, put try-catch.


Comments