Search This Blog

Thursday, February 23, 2017

How to refresh View appearance after making changes to the Application Model in code

With XAF v16.2.4, you can apply Application Model changes to a View without recreating it. To do this, save the Frame's View to a variable and then unlink it from the Frame by passing null to the SetView method. After that, make the required changes to the model, call the LoadModel method with the false parameter and then set the saved View back to the Frame using the SetView method. Here is the generic code illustrating this pattern:

View view = Frame.View;
if(Frame.SetView(null, true, null, false)) {
    // Make required changes with the model here. 
    // ... 

You can find a full ViewController code for accomplishing the two most popular WinForms scenarios benefiting from this capability in the article (switching a ListView editor type and MasterDetailMode). 
This video also illustrates how it works in the application UI in action. 

Leave a comment if this is something you are going to try right now!
As always, please report any issues using the service. Thanks in advance!