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:
CodeView 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.
If you invoke the SwitchMasterDetailMode action from the context menu (WinForms), the context menu stays open
@Andreas: I've created a separate ticket on your behalf (T486898: Context menu stays visible after using a solution from S173664) and just answered it. Thanks.
Hello DevExpress team,
this API extension is very useful, thank you. But there is one problem - It works fine until i have a ListView in Server-Mode (Model -> DataAccessMode = Server). In this case i get InvalidOperationException "Cannot change DefaultSorting property…". This problem is already known (https://www.devexpress.com/Support/Center/Question/Details/Q497593). Do you plan any further APi improvement because of this exception, or what could you suggest us in this situation?
Thank you and best regards.
@Kim_Schmidt: Thanks for your feedback on this new solution - our Core team and I are happy to hear that this is useful for your business.
As for the behavior you experienced, we already made additional checks in our code to avoid it in the most popular cases: The "Cannot change property 'DefaultSorting' when the XPCollection is not in design or initialization mode." error occurs in MainDemo. I have just made sure it was corrected for this particular code after testing the latest v16.2 bits.
Take special note that if you explicitly modify the IModelListView.Sorting node or apply sorting to the CollectionSource directly (we think it falls to rare and advanced scenarios), you will not avoid this exception as expected. Let me know if you think this behavior can be improved further.
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.
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.
Thanks for your update. I need some additional time to research your code and issues with it. Please bear with me.
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.