Closed SuperJMN closed 5 years ago
AFAIK, you can't set a behavior in a style!
Having said that, Cimbalino Toolkit contains an AutoFocusBehavior you can put directly in the root element of your page and it will jump to the next control on Enter!
Thanks for the quick answer! Can this be confirmed by the authors? in case you're not the author of this library :)
I just contribute here but I'm the author of Cimbalino Toolkit (and wrote that specific behavior), so fell free to open an issue in the correct place if you have problems using it! 😄
OK! I hope somebody can confirm it then. I will take a look to the Cimbalino Toolkit, BTW :)
We can do this using pure XAML and a reusable attached property, that receives a DataTemplate with a BehaviorCollection (or a single Behavior). You don't have to change your code-behind.
Is this going to be fixed?
Is this going to be fixed?
I don't think it is a bug. Looks like that's the way Styles work, and XamlBehaviors are designed for elements rather than Styles, which need DataTemplates to make it work. See my answer above for a flexible workaround.
Important: See Sample solution below (zipped file)!
I have created a
OnEnterFocusNextBehavior
that sets the focus to the next element when the user presses the Enter key and I want every TextBox and PasswordBox to have this functionality, by default To do so, I did those StylesI put this XAML inside MainPage to test it. However, it only works on the very first TextBox. I have debugged it and the OnAttached method is only called once.
This is my custom Behavior
Am I doing it wrong?
BehaviorInStyleDemo.zip