Skip to content

Commit f5de847

Browse files
committed
Add dynamic cascasding values sample
1 parent 155fa8d commit f5de847

File tree

13 files changed

+109
-3
lines changed

13 files changed

+109
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Samples for ASP.NET Core 6.0 (487)
1+
# Samples for ASP.NET Core 6.0 (488)
22

3-
- Samples for ASP.NET Core **8.0 Preview 7** is available [here](/projects/.net8) (25).
3+
- Samples for ASP.NET Core **8.0 Preview 7** is available [here](/projects/.net8) (26).
44
- Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
55
- Samples for ASP.NET Core **8.0 Preview 6** using EdgeDB.NET is [here](https://github.com/edgedb/edgedb-net).
66

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dotnet.defaultSolution": "ComponentTwentyFive.sln"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<h1>Page not found</h1>
7+
<p>Sorry, but there's nothing here!</p>
8+
</NotFound>
9+
</Router>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>true</ImplicitUsings>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-preview.7.*" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-preview.7.*" />
9+
<Watch Include="**\*.cshtml" />
10+
<Watch Include="**\*.razor" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
3+
<h1>Dynamic Cascading Values</h1>
4+
Keep refreshing the page to see the date and time change
5+
6+
<InnerComponentOne />
7+
8+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h2>Inner Component One</h2>
2+
3+
@HelloMessage.Message
4+
5+
<InnerComponentTwo />
6+
7+
@code {
8+
[CascadingParameter]
9+
protected MessageCascade HelloMessage { get; set; } = default!;
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<h3>Inner Component Two</h3>
3+
4+
@GoodbyeMessage.Message
5+
6+
@code {
7+
[CascadingParameter]
8+
protected MessageCascade GoodbyeMessage { get; set; } = default!;
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2+
using Microsoft.AspNetCore.Components;
3+
using ComponentTwentyFive;
4+
5+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
6+
builder.RootComponents.Add<App>("app");
7+
builder.Services.AddCascadingValue(sp =>
8+
{
9+
var msg = new MessageCascade("Hello World! " + DateTime.Now);
10+
var source = new CascadingValueSource<MessageCascade>(msg, isFixed: false);
11+
return source;
12+
});
13+
14+
var app = builder.Build();
15+
await app.RunAsync();
16+
17+
public record MessageCascade(string Message);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Setting root level dynamic cascading values
2+
3+
This sample shows how to set root level **dynamic** cascading **values using `CascadingValueSource`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="main">
4+
<div class="content px-4">
5+
@Body
6+
</div>
7+
</div>

0 commit comments

Comments
 (0)