Skip to content
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

Razor Components/Blazor access modifiers #11897

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>

@functions {
int currentCount = 0;
private int currentCount = 0;

void IncrementCount()
private void IncrementCount()
{
currentCount++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@functions {
int currentCount = 0;
private int currentCount = 0;

[Parameter] int IncrementAmount { get; set; } = 1;
[Parameter] private int IncrementAmount { get; set; } = 1;

void IncrementCount()
private void IncrementCount()
{
currentCount += IncrementAmount;
}
Expand Down
4 changes: 2 additions & 2 deletions aspnetcore/client-side/spa/blazor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Explore ASP.NET Core Blazor, a new way to build interactive client-
monikerRange: '>= aspnetcore-3.0'
ms.author: riande
ms.custom: mvc
ms.date: 03/28/2019
ms.date: 04/08/2019
uid: spa/blazor/index
---
# Introduction to Blazor
Expand Down Expand Up @@ -66,7 +66,7 @@ The following markup is an example of a custom dialog component in a Razor file
<div>
<h2>@Title</h2>
@BodyContent
<button onclick=@OnOK>OK</button>
<button onclick="@OnOK">OK</button>
</div>

@functions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</ul>

@functions {
[Parameter] RenderFragment<TItem> ItemTemplate { get; set; }
[Parameter] IReadOnlyList<TItem> Items { get; set; }
[Parameter] private RenderFragment<TItem> ItemTemplate { get; set; }
[Parameter] private IReadOnlyList<TItem> Items { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
@implements ITab

<li>
<a onclick=@Activate class="nav-link @TitleCssClass" role="button">
<a onclick="@Activate" class="nav-link @TitleCssClass" role="button">
@Title
</a>
</li>

@functions {
[CascadingParameter] TabSet ContainerTabSet { get; set; }
[Parameter] string Title { get; set; }
[CascadingParameter] private TabSet ContainerTabSet { get; set; }
[Parameter] private string Title { get; set; }
[Parameter] public RenderFragment ChildContent { get; private set; }

string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;
private string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;

protected override void OnInit()
{
Expand All @@ -25,7 +25,7 @@
ContainerTabSet.RemoveTab(this);
}

void Activate()
private void Activate()
{
ContainerTabSet.SetActivateTab(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

@functions {
[Parameter] RenderFragment ChildContent { get; set; }
[Parameter] private RenderFragment ChildContent { get; set; }

public ITab ActiveTab { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</table>

@functions {
[Parameter] RenderFragment TableHeader { get; set; }
[Parameter] RenderFragment<TItem> RowTemplate { get; set; }
[Parameter] RenderFragment TableFooter { get; set; }
[Parameter] IReadOnlyList<TItem> Items { get; set; }
[Parameter] private RenderFragment TableHeader { get; set; }
[Parameter] private RenderFragment<TItem> RowTemplate { get; set; }
[Parameter] private RenderFragment TableFooter { get; set; }
[Parameter] private IReadOnlyList<TItem> Items { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public class BlazorRocksBase : ComponentBase
{
public string BlazorRocksText { get; set; } = "Blazor rocks the browser!";
public string BlazorRocksText { get; set; } =
"Blazor rocks the browser!";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h4>Greetings from the first tab!</h4>

<label>
<input type="checkbox" bind=@showThirdTab />
<input type="checkbox" bind="@showThirdTab" />
Toggle third tab
</label>
</Tab>
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace BlazorSample.UIInterfaces
&lt;h4&gt;Greetings from the first tab!&lt;/h4&gt;

&lt;label&gt;
&lt;input type="checkbox" bind=@@showThirdTab /&gt;
&lt;input type="checkbox" bind="@@showThirdTab" /&gt;
Toggle third tab
&lt;/label&gt;
&lt;/Tab&gt;
Expand All @@ -68,7 +68,7 @@ namespace BlazorSample.UIInterfaces

@@functions
{
bool showThirdTab;
private bool showThirdTab;
}</code></pre>

<h2>TabSet.csthml</h2>
Expand All @@ -90,7 +90,7 @@ namespace BlazorSample.UIInterfaces
&lt;/div&gt;

@@functions {
[Parameter] RenderFragment ChildContent { get; set; }
[Parameter] private RenderFragment ChildContent { get; set; }

public ITab ActiveTab { get; private set; }

Expand Down Expand Up @@ -129,17 +129,17 @@ namespace BlazorSample.UIInterfaces
@@implements ITab

&lt;li&gt;
&lt;a onclick=@@Activate class="nav-link @@TitleCssClass" role="button"&gt;
&lt;a onclick="@@Activate" class="nav-link @@TitleCssClass" role="button"&gt;
@@Title
&lt;/a&gt;
&lt;/li&gt;

@@functions {
[CascadingParameter] TabSet ContainerTabSet { get; set; }
[Parameter] string Title { get; set; }
[CascadingParameter] private TabSet ContainerTabSet { get; set; }
[Parameter] private string Title { get; set; }
[Parameter] public RenderFragment ChildContent { get; private set; }

string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;
private string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;

protected override void OnInit()
{
Expand All @@ -151,13 +151,13 @@ namespace BlazorSample.UIInterfaces
ContainerTabSet.RemoveTab(this);
}

void Activate()
private void Activate()
{
ContainerTabSet.SetActivateTab(this);
}
}</code></pre>

@functions
{
bool showThirdTab;
private bool showThirdTab;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<p><button class="btn @ThemeInfo.ButtonClass" onclick="@IncrementCount">Increment Counter (Themed)</button></p>

@functions {
int currentCount = 0;
private int currentCount = 0;

[CascadingParameter] protected ThemeInfo ThemeInfo { get; set; }

void IncrementCount()
private void IncrementCount()
{
currentCount++;
}
Expand All @@ -39,7 +39,7 @@
&lt;/div&gt;

@@functions {
ThemeInfo theme = new ThemeInfo { ButtonClass = "btn-success" };
private ThemeInfo theme = new ThemeInfo { ButtonClass = "btn-success" };
}</code></pre>

<p>This component (<em>CascadingValuesParametersTheme.cshtml</em>) receives the <code>ThemeInfo</code> as a <code>CascadingParameter</code>. The parameter is used to style one of the buttons:</p>
Expand All @@ -49,11 +49,11 @@
&lt;button class="btn @@ThemeInfo.ButtonClass" onclick="@@IncrementCount"&gt;Increment Counter (Themed)&lt;/button&gt;

@@functions {
int currentCount = 0;
private int currentCount = 0;

[CascadingParameter] protected ThemeInfo ThemeInfo { get; set; }

void IncrementCount()
private void IncrementCount()
{
currentCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h1 style="font-style:@_headingFontStyle">@_headingText</h1>

<form>
<div class="form-check">
<div class="form-check" style="margin-left:1.5rem">
@*
A check box sets the font style and is bound to the
_italicsCheck field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@petTemplate(new Pet { Name = "Rex" })

@functions {
List<Pet> pets = new List<Pet>
private List<Pet> pets = new List<Pet>
{
new Pet { PetId = 1, Name = "Rin Tin Tin" },
new Pet { PetId = 2, Name = "Mr. Bigglesworth" },
Expand All @@ -37,7 +37,7 @@
new Pet { PetId = 7, Name = "K-9" }
};

class Pet
private class Pet
{
public int PetId { get; set; }
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</ListViewTemplate>

@functions {
List<Pet> pets = new List<Pet>
private List<Pet> pets = new List<Pet>
{
new Pet { PetId = 1, Name = "Rin Tin Tin" },
new Pet { PetId = 2, Name = "Mr. Bigglesworth" },
Expand All @@ -105,7 +105,7 @@
new Pet { PetId = 7, Name = "K-9" }
};

class Pet
private class Pet
{
public int PetId { get; set; }
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
</div>

@functions {
ThemeInfo theme = new ThemeInfo { ButtonClass = "btn-success" };
private ThemeInfo theme =
new ThemeInfo { ButtonClass = "btn-success" };
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
</div>

@functions {
bool collapseNavMenu = true;
private bool collapseNavMenu = true;

string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

void ToggleNavMenu()
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</ul>

@functions {
[Parameter] RenderFragment<TItem> ItemTemplate { get; set; }
[Parameter] IReadOnlyList<TItem> Items { get; set; }
[Parameter] private RenderFragment<TItem> ItemTemplate { get; set; }
[Parameter] private IReadOnlyList<TItem> Items { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public class BlazorRocksBase : ComponentBase
{
public string BlazorRocksText { get; set; } = "Blazor rocks the browser!";
public string BlazorRocksText { get; set; } =
"Blazor rocks the browser!";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h4>Greetings from the first tab!</h4>

<label>
<input type="checkbox" bind=@showThirdTab />
<input type="checkbox" bind="@showThirdTab" />
Toggle third tab
</label>
</Tab>
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace RazorComponents.UIInterfaces
&lt;h4&gt;Greetings from the first tab!&lt;/h4&gt;

&lt;label&gt;
&lt;input type="checkbox" bind=@@showThirdTab /&gt;
&lt;input type="checkbox" bind="@@showThirdTab" /&gt;
Toggle third tab
&lt;/label&gt;
&lt;/Tab&gt;
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace RazorComponents.UIInterfaces
&lt;/div&gt;

@@functions {
[Parameter] RenderFragment ChildContent { get; set; }
[Parameter] private RenderFragment ChildContent { get; set; }

public ITab ActiveTab { get; private set; }

Expand Down Expand Up @@ -129,17 +129,17 @@ namespace RazorComponents.UIInterfaces
@@implements ITab

&lt;li&gt;
&lt;a onclick=@@Activate class="nav-link @@TitleCssClass" role="button"&gt;
&lt;a onclick="@@Activate" class="nav-link @@TitleCssClass" role="button"&gt;
@@Title
&lt;/a&gt;
&lt;/li&gt;

@@functions {
[CascadingParameter] TabSet ContainerTabSet { get; set; }
[Parameter] string Title { get; set; }
[CascadingParameter] private TabSet ContainerTabSet { get; set; }
[Parameter] private string Title { get; set; }
[Parameter] public RenderFragment ChildContent { get; private set; }

string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;
private string TitleCssClass => ContainerTabSet.ActiveTab == this ? "active" : null;

protected override void OnInit()
{
Expand All @@ -151,13 +151,13 @@ namespace RazorComponents.UIInterfaces
ContainerTabSet.RemoveTab(this);
}

void Activate()
private void Activate()
{
ContainerTabSet.SetActivateTab(this);
}
}</code></pre>

@functions
{
bool showThirdTab;
private bool showThirdTab;
}
Loading