Phone800.366.3472 SupportGet Support DocumentationDocumentation Resource CenterResource Center
Open Menu

Synergex Blog

Keeping Focus

By Richard Morris, Posted on August 15, 2012 at 6:56 am


In a traditional Synergy application you have usually always had total control over the user interface.  Your program code has displayed the field prompts on the screen, or loaded and placed your UI Toolkit windows.  With the user interface defined and displayed it’s again your application code that controls what the user can do, and when.  If they enter an invalid value in a field the code would usually display some sort of message and force the user back into the field, never to leave until a valid (according again to your application logic) value has been entered.  And the UI Toolkit continues this tight coupling between field validation, user notification and UI navigation control.

As software development moved forward with Microsoft WinForms based applications this trend generally followed.  The code behind each control knows everything about the control, and as such can force the focus back to the field when required.

With the advent of the Windows Presentation Foundation (WPF) application things changed dramatically.  Of course you can still bind code-behind to your controls on your WPF forms, but that’s really not the point of WPF – if you have code behind then the chances are you are going something wrong.  The most powerful feature of WPF is data binding.  Data binding is the ability to bind an object property value to a field or control on your user interface.  Messaging between the UI and the application ensure that your data is kept synchronised.  This is the Model-View-View Model (MVVM) design approach, which is the cornerstone of a Symphony Framework based Synergy .NET WPF application.  MVVM provides for a platform that fully (and correctly) disconnects the user interface from the application data and logic.  But if the application has no knowledge of the UI, and the UI has no knowledge of the application logic, how can your programs force fields on your forms to have focus?  There are many better ways to provide user feedback than to display modal messages and force the user back into the field entry, which I’ll discuss in a future blog.  But there will always be someone who needs to be able to re-focus a field within the user interface from within their program.  Code-behind will be required, yes?  No, not if you use a Symphony Framework Data Object!

Symphony Framework provides the ability to request focus be given to whatever control you are using to bind against a particular Data Object property.  And focusing that control is the responsibility of the View, or XAML code – there is no code-behind requirement.  From within you application you can set a property in the Symphony Framework Data Object indicating that you would like the control associated with that data property to be given focus.  In the XAML you listen for the request and honour it or not, at the discretion of the UI designer.  And that request can bound to simple controls or complex containers.

Do you want to know how?  Instead of writing up lots of code I’ve prepared a short video that demonstrates this powerful new feature of the Symphony Framework.  You can view the video on YouTube by clicking this link: Happy viewing!

Leave a Reply

Your email address will not be published. Required fields are marked *


Don't miss a post!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Posts Categories Tag Cloud Archives