KB Article S173664
Visible to All Users

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:

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

You can find a full ViewController code for accomplishing the two most popular WinForms scenarios benefiting from this capability in the online documentation at Task-Based Help > How to: Apply Application Model Changes to the Current View Immediately. The attached HowItWorksInAction.swf video illustrates the results in the application UI.

See also:
Core - Provide a platform-independent solution for reloading View settings after customizing its Application Model information

Show previous comments (4)

    Hello Dennis,
    Yes, this feature is quite important for our application, so thank you again for working in it.
    Unfortunately, after careful testing, I noticed that we can’t use this improvement in our application yet. I found some problems and gathered them in attached solution. For now we stay with “old” approach – recreate view.

    1. Problem – start ListView “Test Bo 1” and execute 2 times action “SwitchMasterDetailMode” -> NRE should be thrown. This is a small bug, I guess.
    2. Problem – start ListView “Test Bo 2” and execute action “SwitchEditor”… OK, the problem is understandable, but what to do with it? Now we avoid this problem, because we set DataAccessMode = Client to the View.Model during View recreating if the editor does not support server mode. In case with Frame.SetView(…) without View recreating it does not work, because the collection source of the View is already created. I didn’t find any solution for this scenario, but just forbid the action if desired editor can’t work in server mode is not the appropriate solution for us.
    3. Problem – start ListView “Test Bo 3”. The view stated already in master-detail mode and if you click on the “Prop Bool” check box, you will be notified about very important code execution. Now execute “SwitchMasterDetailMode” action twice, click “Prop Bool” again – nothing happens. To understand this please take a look to the MyVeryImportantController in the attached solution, I wrote some comments there in source code.
      I can understand this problem as well, and I can even avoid it with extending of MyVeryImportantController with Frame.ViewChanged event handler, for example, but the problem is – we have a lot of controllers, which track the current object changes… I wish to have some option to notify all such controllers, and in my opinion it could be View.CurrentObjectChanged event, but I couldn’t find any chance to force it – any manipulation with GridView.FocusedRowHandle were unsuccessful.
      Let me know if description of my problems was insufficient, I’ll give you more details.
      Thank you for your assistance and best regards.
    Dennis Garavsky (DevExpress) 8 years ago

      Thanks for your update. I need some additional time to research your code and issues with it. Please bear with me.

      Dennis Garavsky (DevExpress) 8 years ago

        Hello,

        1. I've created a separate ticket on your behalf (T512772: TreeListEditor - NullReferenceException occurs on the second ListView recreation after changing the corresponding Application Model node) and responsible developers from our Core squad will work on a fix.
        2. I've just described an alternative solution in the T512781: How to switch between TreeListEditor and GridListEditor in a ListView with DataAccessMode = Server and avoid InvalidOperationException (X does not support Server Mode) ticket.
        3. I've created a separate ticket on your behalf (The View.CurrentObjectChanged event is not raised on the second ListView recreation after changing the corresponding Application Model node) and you will be automatically notified once we finish our research.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.