expressappframework-113653-ui-construction-view-items-and-property-editors-add-a-button-to-a-detail-view-using-custom-view-item.md
This article describes how to add a custom control to a Detail View. If you want to display standard XAF Actions in a Detail View, use the technique described in the following topic: How to Add an Unbound Control (Button) to the Form Layout in an XAF View (with a Built-in ActionContainerViewItem).
A custom View Item should be a ViewItem descendant. You can also inherit it from any of the built-in View Items that XAF supplies. For more information about View Items, refer to the following topic: View Items
This is an advanced customization method that requires coding. Use it when you want to add an existing or custom control to the client area of a Detail View or Dashboard View. This approach allows you to obtain data from the current View object if necessary. Your control can be unbound or can load data from external sources.
If you want to bind a control to a business class property and add that control to both List View and Detail View, then consider the custom Property Editor approach.
This approach does not impose any restrictions on UI Control and XAF View interaction. You can implement custom logic in a ViewController or a custom UI control. ViewItem descendants may implement their own inner logic.
View Example: How to: Use a Custom View Item to Add a Button to a Detail View (ASP.NET Core Blazor)
Add a Razor component (Button.razor in this example) to the ASP.NET Core Blazor application project (MySolution.Blazor.Server). In this component, configure the DxButton component.
Ensure that the component’s Build Action property is set to Content.
Create a ComponentModelBase descendant and name it ButtonModel. In this class, add properties and methods that describe your component.
Add the ButtonDetailViewItemBlazor View Item to the ASP.NET Core Blazor application project (MySolution.Blazor.Server).
View Example: XAF - Add a Custom Button to a Form (WinForms)
Add the ButtonDetailViewItemWin View Item to the WinForms application project (MySolution.Win). Decorate this View Item with ViewItemAttribute to make this View Item appear in the Application Model‘s ViewItems node.
Add the new View Item to the Detail View. Open the Model Editor and navigate to the Views | MySolution.Module.BusinessObjects | <Class> | <Class>_DetailView | Items node. Right-click the node and select ButtonDetailViewItemWin from the Add context menu options.
Navigate to the Views | MySolution.Module.BusinessObjects | <Class> | <Class>_DetailView | Layout node. Right-click the layout area and select the Customize Layout option from the context menu. Drag the new View Item from the Customization window to the layout area.
See Also
Add an Unbound Control (Button) to the Form Layout in an XAF View
Implement a Property Editor Based on a Custom Component (Blazor)
How to: Use a Custom Component to Implement List Editor (Blazor)