wpf - Focus first textbox in some ListBox item -


i have listbox listbox.itemtemplate contains labels , textboxes.

i want focus first textbox of last item programatically. how can that?

i don't know how can access textbox object created dynamically data binding.

try use behaviour (code not mine - https://gist.github.com/tswann/892163)

using system; using system.windows;  namespace myproject.wpf.helpers {     /// <summary>     /// allows arbitrary ui element bind keyboard focus attached property.     /// </summary>     public static class focusbehaviour     {         public static bool gethaskeyboardfocus(dependencyobject obj)         {             return (bool)obj.getvalue(haskeyboardfocusproperty);         }          public static void sethaskeyboardfocus(dependencyobject obj, bool value)         {             obj.setvalue(haskeyboardfocusproperty, value);         }          // using dependencyproperty backing store haskeyboardfocus.  enables animation, styling, binding, etc...         public static readonly dependencyproperty haskeyboardfocusproperty =             dependencyproperty.registerattached("haskeyboardfocus",              typeof(bool),              typeof(focusbehaviour),              new uipropertymetadata(false, null, coercecurrentvalue));          /// <summary>         /// coerce property value , give focus bound control if true.         /// </summary>         /// <param name="source">uielement property has been attached.</param>         /// <param name="value">property value</param>         /// <returns>property value</returns>         private static object coercecurrentvalue(dependencyobject source, object value)         {             uielement control = source uielement;             if (control != null)             {                 bool hasfocus = (bool)value;                  if (hasfocus)                 {                     system.threading.threadpool.queueuserworkitem((a) =>                     {                          control.dispatcher.invoke(new action(() =>                          {                              control.focus();                          }));                     });                  }             }              return value;         }     } } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -