wpf - UIElement.Focus() does not work, why? -


my wpf window has button , listview. on button's click event, has following code.

private void mybutton1_click(object sender, routedeventargs e) {     listviewitem lvi = new listviewitem()     {         content = "hello",         focusable = true,         isenabled = true     };     this.listview1.items.add(lvi);     lvi.focus(); } 

here problem, focus cannot move lvi(listviewitem), after user clicks button. code lvi.focus() not have effect. can tell me why happens, , how can solve it?

update:

find solution. call code, otherwise focus still captured button.

this.dispatcher.begininvoke(new action(() => lvi.focus()), system.windows.threading.dispatcherpriority.input); 

try following:

listviewitem lvi = new listviewitem(); lvi.isselected = true; 

hope helps ;)


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -