To change the default page size globally, consider one of the following solutions depending on your business needs (they are listed in the order of preference or simplicity):
1. Perform Application Model customizations via the Model Editor invoked at design time or at runtime.
For instance, you can change the default IModelListView.PageSize value for each Views | ListView node manually using the Model Editor. This manual process can be inappropriate if there are too many ListView nodes where you want to apply these changes.
2. Automate Application Model customizations using one of the methods below or their combination.
2.1. Create a Model Nodes Generator Updater class for the ModelViewsNodesGenerator type, iterate through all ListView models in it and change their IModelListViewWeb.PageSize property. Refer to the Extend and Customize the Application Model in Code topic and the code snippet below for additional information:
C#using System;
using System.Linq;
using System.ComponentModel;
using DevExpress.ExpressApp;
using System.Collections.Generic;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Updating;
using DevExpress.ExpressApp.Model.Core;
using DevExpress.ExpressApp.Web.SystemModule;
using DevExpress.ExpressApp.Model.NodeGenerators;
namespace MainDemo.Module.Web {
public sealed partial class MainDemoWebModule : ModuleBase {
public MainDemoWebModule() {
InitializeComponent();
}
public override void AddGeneratorUpdaters(ModelNodesGeneratorUpdaters updaters) {
base.AddGeneratorUpdaters(updaters);
updaters.Add(new T271022());
}
internal class T271022 : ModelNodesGeneratorUpdater<ModelViewsNodesGenerator> {
public override void UpdateNode(ModelNode viewsNode) {
foreach(IModelListViewWeb modelListView in ((IModelViews)viewsNode).Where(mv => mv is IModelListViewWeb)) {
modelListView.PageSize = 50;
}
}
}
...
}
}
Take special note that node generators and node updaters work at the "zero" layer and thus have no access to higher Application Model layers where cloned/copied nodes or other model differences reside. Also, all settings made there will NOT be saved in user model differences. This is the default behavior of the Application Model and you can learn more about it from the eXpressApp Framework > Concepts > Application Model > Application Model Basics article.
2.2. Implement a custom Get domain logic for the required property. See an example in the Change the default value in application model ticket. Note that this logic should always return a value, and the default value cannot be obtained. So, use this solution only when it is necessary to override all values. The Get domain logic is executed each time the value of the corresponding model property is requested. So, this approach may be useful when it is necessary to calculate a property value based on runtime variables, such as the current user name. Values specified in the Get logic can be overridden in higher-level Application Model layers - e.g., by user-defined settings.
2.3. Handle various events of the XafApplication and other objects after the Application Model was generated:
SetupComplete - if you want to perform adjustments before user differences are loaded. All customizations made at this time will NOT be saved in user model differences.
UserDifferencesLoaded - if you want to perform adjustments after the user differences are loaded. All customizations made at this time or in later events will be saved in the user model differences as well, which may increase their size.
ViewCreating, ListViewCreating and similar events - have the same effect as the UserDifferencesLoaded event, but the changes will be applied on demand, after each View is really created in the UI and not at once (aka "lazy loading").
The code example below demonstrate how these events can be handled in the YourSolutionName.Module/Module.cs file:
C#using System;
using System.Linq;
using DevExpress.ExpressApp;
using System.Threading.Tasks;
using DevExpress.ExpressApp.Model;
namespace MainDemo.Module {
public sealed partial class MainDemoModule : ModuleBase {
public override void Setup(XafApplication application) {
base.Setup(application);
application.ListViewCreating += application_ListViewCreating;
application.UserDifferencesLoaded += CustomizeAllViewsAtOnceDemo;
application.SetupComplete += CustomizeAllViewsAtOnceDemo;
}
void CustomizeAllViewsAtOnceDemo(object sender, EventArgs e) {
Parallel.ForEach(((XafApplication)sender).Model.Views.OfType<IModelListView>(),
modelListView => modelListView.MasterDetailMode = MasterDetailMode.ListViewAndDetailView);
}
void application_ListViewCreating(object sender, ListViewCreatingEventArgs e) {
IModelListView modeListView = ((XafApplication)sender).FindModelView(e.ViewID) as IModelListView;
if(modeListView != null) {
modeListView.MasterDetailMode = MasterDetailMode.ListViewAndDetailView;
}
}
public MainDemoModule() {
InitializeComponent();
}
}
}
3. Do not perform customizations at the Application Model level, but rather customize the control directly where possible.
For instance, you can implement a ViewController to access ASPxGridView and customize its SettingsPager.PageSize property.
See the Access Grid Control Properties in ASP.NET Web Applications help topic for sample code.
IMPORTANT NOTES:
Any changes made to the Application Model are not immediately reflected in the UI. Customize the application model before the control used to display the target UI element is created and loaded. If it is necessary to customize the UI element after its control is created and initialized with default settings, access the control directly (see Access Editor Settings, Access Grid Control Properties, etc.).
See Also:
How to implement a custom attribute to customize the Application Model
How to refresh View appearance after making changes to the Application Model in code
Concepts > Application Model > Extend and Customize the Application Model in Code