-
Notifications
You must be signed in to change notification settings - Fork 2
Update custom view item example to follow modern best practices #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arkady15
merged 4 commits into
DevExpress-Examples:25.2.1+
from
ebryliakov:fix/unbound-control-parameters
Dec 10, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
CS/EFCore/CustomViewItem/CustomViewItem.Blazor.Server/Editors/ButtonViewItem/Button.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| @namespace CustomViewItem.Blazor.Server.Editors.ButtonViewItem | ||
|
|
||
| <DxButton Text=@Text Click=@Click /> | ||
|
|
||
| @code { | ||
| [Parameter] | ||
| public string Text { get; set; } | ||
| [Parameter] | ||
| public EventCallback<MouseEventArgs> Click { get; set; } | ||
| } |
69 changes: 33 additions & 36 deletions
69
...iewItem/CustomViewItem.Blazor.Server/Editors/ButtonViewItem/ButtonDetailViewItemBlazor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,42 @@ | ||
| using System; | ||
| using DevExpress.ExpressApp; | ||
| using DevExpress.ExpressApp; | ||
| using DevExpress.ExpressApp.Blazor; | ||
| using DevExpress.ExpressApp.Blazor.Components; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using DevExpress.ExpressApp.Editors; | ||
| using DevExpress.ExpressApp.Model; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
|
|
||
| using DevExpress.ExpressApp.Blazor.Components; | ||
| namespace CustomViewItem.Blazor.Server.Editors.ButtonViewItem; | ||
|
|
||
| public interface IModelButtonDetailViewItemBlazor : IModelViewItem; | ||
|
|
||
| namespace MySolution.Module.Blazor { | ||
| public interface IModelButtonDetailViewItemBlazor : IModelViewItem { } | ||
| [ViewItem(typeof(IModelButtonDetailViewItemBlazor))] | ||
| public class ButtonDetailViewItemBlazor(IModelViewItem model, Type objectType) : | ||
| ViewItem(objectType, model.Id), | ||
| IComponentContentHolder, | ||
| IComplexViewItem | ||
| { | ||
| public ButtonModel ComponentModel => componentModel; | ||
|
|
||
| private ButtonModel componentModel; | ||
| private XafApplication application; | ||
|
|
||
| [ViewItem(typeof(IModelButtonDetailViewItemBlazor))] | ||
| public class ButtonDetailViewItemBlazor : ViewItem, IComplexViewItem { | ||
| public class ButtonHolder : IComponentContentHolder { | ||
| public ButtonHolder(ButtonModel componentModel) { | ||
| ComponentModel = componentModel; | ||
| } | ||
| public ButtonModel ComponentModel { get; } | ||
| RenderFragment IComponentContentHolder.ComponentContent => ComponentModelObserver.Create(ComponentModel, ButtonRenderer.Create(ComponentModel)); | ||
| } | ||
| private XafApplication application; | ||
| public ButtonDetailViewItemBlazor(IModelViewItem model, Type objectType) : base(objectType, model.Id) { } | ||
| void IComplexViewItem.Setup(IObjectSpace objectSpace, XafApplication application) { | ||
| this.application = application; | ||
| } | ||
| protected override object CreateControlCore() => new ButtonHolder(new ButtonModel()); | ||
| protected override void OnControlCreated() { | ||
| if (Control is ButtonHolder holder) { | ||
| holder.ComponentModel.Text = "Click me!"; | ||
| holder.ComponentModel.Click += ComponentModel_Click; | ||
| } | ||
| base.OnControlCreated(); | ||
| } | ||
| public override void BreakLinksToControl(bool unwireEventsOnly) { | ||
| if (Control is ButtonHolder holder) { | ||
| holder.ComponentModel.Click -= ComponentModel_Click; | ||
| } | ||
| base.BreakLinksToControl(unwireEventsOnly); | ||
| } | ||
| private void ComponentModel_Click(object sender, EventArgs e) { | ||
| application.ShowViewStrategy.ShowMessage("Action is executed!"); | ||
| } | ||
| RenderFragment IComponentContentHolder.ComponentContent => | ||
| ComponentModelObserver.Create(componentModel, componentModel.GetComponentContent()); | ||
| void IComplexViewItem.Setup(IObjectSpace objectSpace, XafApplication application) { | ||
| this.application = application; | ||
| } | ||
|
|
||
| protected override object CreateControlCore() { | ||
| componentModel = new ButtonModel | ||
| { | ||
| Text = "Click me!", | ||
| Click = EventCallback.Factory.Create<MouseEventArgs>(this, ComponentModel_Click), | ||
| }; | ||
| return componentModel; | ||
| } | ||
| private void ComponentModel_Click() { | ||
| application.ShowViewStrategy.ShowMessage("Action is executed!"); | ||
| } | ||
| } | ||
27 changes: 15 additions & 12 deletions
27
CS/EFCore/CustomViewItem/CustomViewItem.Blazor.Server/Editors/ButtonViewItem/ButtonModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| using System; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
|
|
||
| namespace MySolution.Module.Blazor { | ||
| public class ButtonModel : ComponentModelBase { | ||
| public string Text { | ||
| get => GetPropertyValue<string>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
| public void ClickFromUI() { | ||
| Click?.Invoke(this, EventArgs.Empty); | ||
| } | ||
| public event EventHandler Click; | ||
| namespace CustomViewItem.Blazor.Server.Editors.ButtonViewItem; | ||
|
|
||
| public class ButtonModel : ComponentModelBase { | ||
| public string Text { | ||
| get => GetPropertyValue<string>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
| public EventCallback<MouseEventArgs> Click { | ||
| get => GetPropertyValue<EventCallback<MouseEventArgs>>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
|
|
||
| public override Type ComponentType => typeof(Button); | ||
| } |
11 changes: 0 additions & 11 deletions
11
...e/CustomViewItem/CustomViewItem.Blazor.Server/Editors/ButtonViewItem/ButtonRenderer.razor
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
CS/EFCore/CustomViewItem/CustomViewItem.Blazor.Server/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "profiles": { | ||
| "CustomViewItem.Blazor.Server": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
CS/XPO/CustomViewItemXPO/CustomViewItemXPO.Blazor.Server/Editors/ButtonViewItem/Button.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| @namespace CustomViewItemXPO.Blazor.Server.Editors.ButtonViewItem | ||
|
|
||
| <DxButton Text=@Text Click=@Click /> | ||
|
|
||
| @code { | ||
| [Parameter] | ||
| public string Text { get; set; } | ||
| [Parameter] | ||
| public EventCallback<MouseEventArgs> Click { get; set; } | ||
| } |
71 changes: 34 additions & 37 deletions
71
...mXPO/CustomViewItemXPO.Blazor.Server/Editors/ButtonViewItem/ButtonDetailViewItemBlazor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,42 @@ | ||
| using System; | ||
| using DevExpress.ExpressApp; | ||
| using DevExpress.ExpressApp; | ||
| using DevExpress.ExpressApp.Blazor; | ||
| using DevExpress.ExpressApp.Blazor.Components; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using DevExpress.ExpressApp.Editors; | ||
| using DevExpress.ExpressApp.Model; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
|
|
||
| using DevExpress.ExpressApp.Blazor.Components; | ||
| namespace CustomViewItemXPO.Blazor.Server.Editors.ButtonViewItem; | ||
|
|
||
| public interface IModelButtonDetailViewItemBlazor : IModelViewItem; | ||
|
|
||
| namespace MySolution.Module.Blazor { | ||
| public interface IModelButtonDetailViewItemBlazor : IModelViewItem { } | ||
| [ViewItem(typeof(IModelButtonDetailViewItemBlazor))] | ||
| public class ButtonDetailViewItemBlazor(IModelViewItem model, Type objectType) : | ||
| ViewItem(objectType, model.Id), | ||
| IComponentContentHolder, | ||
| IComplexViewItem | ||
| { | ||
| public ButtonModel ComponentModel => componentModel; | ||
|
|
||
| private ButtonModel componentModel; | ||
| private XafApplication application; | ||
|
|
||
| [ViewItem(typeof(IModelButtonDetailViewItemBlazor))] | ||
| public class ButtonDetailViewItemBlazor : ViewItem, IComplexViewItem { | ||
| public class ButtonHolder : IComponentContentHolder { | ||
| public ButtonHolder(ButtonModel componentModel) { | ||
| ComponentModel = componentModel; | ||
| } | ||
| public ButtonModel ComponentModel { get; } | ||
| RenderFragment IComponentContentHolder.ComponentContent => ComponentModelObserver.Create(ComponentModel, ButtonRenderer.Create(ComponentModel)); | ||
| } | ||
| private XafApplication application; | ||
| public ButtonDetailViewItemBlazor(IModelViewItem model, Type objectType) : base(objectType, model.Id) { } | ||
| void IComplexViewItem.Setup(IObjectSpace objectSpace, XafApplication application) { | ||
| this.application = application; | ||
| } | ||
| protected override object CreateControlCore() => new ButtonHolder(new ButtonModel()); | ||
| protected override void OnControlCreated() { | ||
| if (Control is ButtonHolder holder) { | ||
| holder.ComponentModel.Text = "Click me!"; | ||
| holder.ComponentModel.Click += ComponentModel_Click; | ||
| } | ||
| base.OnControlCreated(); | ||
| } | ||
| public override void BreakLinksToControl(bool unwireEventsOnly) { | ||
| if (Control is ButtonHolder holder) { | ||
| holder.ComponentModel.Click -= ComponentModel_Click; | ||
| } | ||
| base.BreakLinksToControl(unwireEventsOnly); | ||
| } | ||
| private void ComponentModel_Click(object sender, EventArgs e) { | ||
| application.ShowViewStrategy.ShowMessage("Action is executed!"); | ||
| } | ||
| RenderFragment IComponentContentHolder.ComponentContent => | ||
| ComponentModelObserver.Create(componentModel, componentModel.GetComponentContent()); | ||
| void IComplexViewItem.Setup(IObjectSpace objectSpace, XafApplication application) { | ||
| this.application = application; | ||
| } | ||
|
|
||
| protected override object CreateControlCore() { | ||
| componentModel = new ButtonModel | ||
| { | ||
| Text = "Click me!", | ||
| Click = EventCallback.Factory.Create<MouseEventArgs>(this, ComponentModel_Click), | ||
| }; | ||
| return componentModel; | ||
| } | ||
| private void ComponentModel_Click() { | ||
| application.ShowViewStrategy.ShowMessage("Action is executed!"); | ||
| } | ||
| } | ||
| } |
29 changes: 16 additions & 13 deletions
29
...O/CustomViewItemXPO/CustomViewItemXPO.Blazor.Server/Editors/ButtonViewItem/ButtonModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| using System; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using DevExpress.ExpressApp.Blazor.Components.Models; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
|
|
||
| namespace MySolution.Module.Blazor { | ||
| public class ButtonModel : ComponentModelBase { | ||
| public string Text { | ||
| get => GetPropertyValue<string>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
| public void ClickFromUI() { | ||
| Click?.Invoke(this, EventArgs.Empty); | ||
| } | ||
| public event EventHandler Click; | ||
| namespace CustomViewItemXPO.Blazor.Server.Editors.ButtonViewItem; | ||
|
|
||
| public class ButtonModel : ComponentModelBase { | ||
| public string Text { | ||
| get => GetPropertyValue<string>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
| public EventCallback<MouseEventArgs> Click { | ||
| get => GetPropertyValue<EventCallback<MouseEventArgs>>(); | ||
| set => SetPropertyValue(value); | ||
| } | ||
| } | ||
|
|
||
| public override Type ComponentType => typeof(Button); | ||
| } |
11 changes: 0 additions & 11 deletions
11
...omViewItemXPO/CustomViewItemXPO.Blazor.Server/Editors/ButtonViewItem/ButtonRenderer.razor
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
CS/XPO/CustomViewItemXPO/CustomViewItemXPO.Blazor.Server/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "profiles": { | ||
| "CustomViewItemXPO.Blazor.Server": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.