diff --git a/README.md b/README.md index 2067d3ae1..fdf32c99d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # BlazorWebFormsComponents A collection of Blazor components that emulate the web forms components of the same name +[![Build status](https://dev.azure.com/FritzAndFriends/BlazorWebFormsComponents/_apis/build/status/BlazorWebFormsComponents-.NET%20Standard-CI)](https://dev.azure.com/FritzAndFriends/BlazorWebFormsComponents/_build/latest?definitionId=14) + ## Controls proposed to be migrated There are a significant number of controls in ASP.NET Web Forms, and we will focus on creating components in the following order: diff --git a/samples/BeforeWebForms/BeforeWebForms.csproj b/samples/BeforeWebForms/BeforeWebForms.csproj index 65d5f4db2..9054ae9dd 100644 --- a/samples/BeforeWebForms/BeforeWebForms.csproj +++ b/samples/BeforeWebForms/BeforeWebForms.csproj @@ -44,6 +44,9 @@ 4 + + ..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + @@ -99,11 +102,6 @@ ..\..\src\packages\Microsoft.AspNet.FriendlyUrls.Core.1.0.2\lib\net45\Microsoft.AspNet.FriendlyUrls.dll - - - ..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - - @@ -111,6 +109,7 @@ + @@ -168,6 +167,13 @@ Default.aspx + + ModelBinding.aspx + ASPXCodeBehind + + + ModelBinding.aspx + Default.aspx ASPXCodeBehind @@ -250,8 +256,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + +} + +@{ + + var rowCounter = 0; + +} + +@if (!Visible) { + +} +else if (Items == null || !Items.Any()) +{ + @EmptyDataTemplate +} +else +{ + @foreach (var item in Items) + { + + @if (AlternatingItemTemplate == null || rowCounter % 2 == 0) + { + @ItemTemplate(item) + } + else + { + @AlternatingItemTemplate(item) + } + + @if (ItemSeparatorTemplate != null) { + @ItemSeparatorTemplate + } + + rowCounter++; + + } +} diff --git a/src/BlazorWebFormsComponents/ListView.razor.cs b/src/BlazorWebFormsComponents/ListView.razor.cs index 808855a1b..db1d06b5b 100644 --- a/src/BlazorWebFormsComponents/ListView.razor.cs +++ b/src/BlazorWebFormsComponents/ListView.razor.cs @@ -6,37 +6,46 @@ namespace BlazorWebFormsComponents { - public partial class ListView + public partial class ListView : ModelBindingComponent { - [Parameter] - public IEnumerable Items { get; set; } - - [Parameter] - public IEnumerable DataSource + public ListView() { - get { return Items; } - set { Items = value; } } + [Parameter] + public RenderFragment AlternatingItemTemplate { get; set; } + /// + /// Defines the content to render if the data source returns no data. + /// [Parameter] public RenderFragment EmptyDataTemplate { get; set; } [Parameter] - public RenderFragment LayoutTemplate { get; set; } + public RenderFragment ItemSeparatorTemplate { get; set; } [Parameter] - public RenderFragment TableHeader { get; set; } + public RenderFragment ItemTemplate { get; set; } + /// + /// 🚨🚨 LayoutTemplate is not available. Please wrap the ListView component with the desired layout 🚨🚨 + /// [Parameter] - public RenderFragment ItemTemplate { get; set; } + [Obsolete("The LayoutTemplate child element is not supported in Blazor. Instead, wrap the ListView component with the desired layout")] + public RenderFragment LayoutTemplate { get; set; } + + [Parameter] // TODO: Implement + public InsertItemPosition InsertItemPosition { get; set; } - [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + [Parameter] // TODO: Implement + public int SelectedIndex { get; set; } - [Obsolete("This method doesn't do anything in Blazor")] - public void DataBind() { } + /// + /// Style is not applied by this control + /// + [Parameter, Obsolete("Style is not applied by this control")] + public string Style { get; set; } } diff --git a/src/BlazorWebFormsComponents/ModelBindingComponent.cs b/src/BlazorWebFormsComponents/ModelBindingComponent.cs new file mode 100644 index 000000000..26eaa5b0d --- /dev/null +++ b/src/BlazorWebFormsComponents/ModelBindingComponent.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace BlazorWebFormsComponents +{ + + public abstract class ModelBindingComponent : BaseWebFormsComponent { + + // Cheer 300 svavablount 15/12/19 + // Cheer 200 nothing_else_matters 15/12/19 + + public delegate IQueryable SelectHandler(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount); + + /// + /// Data retrieval method to databind the collection to + /// + [Parameter] + public SelectHandler SelectMethod { get; set; } + + [Parameter] + public IEnumerable Items { get; set; } + + [Parameter] + public IEnumerable DataSource + { + get { return Items; } + set { + Items = value; + this.StateHasChanged(); + } + } + + protected override void OnAfterRender(bool firstRender) + { + + if (firstRender && SelectMethod != null) { + + int totalRowCount; + Items = SelectMethod(int.MaxValue, 0, "", out totalRowCount); + StateHasChanged(); + + } + + base.OnAfterRender(firstRender); + + } + + + } + +} diff --git a/src/BlazorWebFormsComponents/_Imports.razor b/src/BlazorWebFormsComponents/_Imports.razor index 77285129d..36d9817c3 100644 --- a/src/BlazorWebFormsComponents/_Imports.razor +++ b/src/BlazorWebFormsComponents/_Imports.razor @@ -1 +1,3 @@ -@using Microsoft.AspNetCore.Components.Web +@inherits BaseWebFormsComponent + +@using Microsoft.AspNetCore.Components.Web