Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blazor 0.7.0 experimental release now available

#1
Blazor 0.7.0 experimental release now available

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/11/blazor-0-7-0-experimental-release-now-available.png" width="596" height="288" title="" alt="" /></div><div><p>Blazor 0.7.0 is now available! This release focuses on enabling component coordination across ancestor-descendent relationships. We’ve also added some improvements to the debugging experience.</p>
<p>Here’s what’s new in the Blazor 0.7.0 release:</p>
<ul>
<li>Cascading values and parameters</li>
<li>Debugging improvements</li>
</ul>
<p>A full list of the changes in this release can be found in the <a href="https://github.com/aspnet/Blazor/releases/tag/0.7.0">Blazor 0.7.0 release notes</a>.</p>
<h2 id="get-blazor-0-7-0">Get Blazor 0.7.0</h2>
<p>Install the following:</p>
<ol>
<li><a href="https://go.microsoft.com/fwlink/?linkid=873092">.NET Core 2.1 SDK</a> (2.1.500 or later).</li>
<li><a href="https://go.microsoft.com/fwlink/?linkid=873093">Visual Studio 2017</a> (15.9 or later) with the <em>ASP.NET and web development</em> workload selected.</li>
<li>The latest <a href="https://go.microsoft.com/fwlink/?linkid=870389">Blazor Language Services extension</a> from the Visual Studio Marketplace.</li>
<li>
<p>The Blazor templates on the command-line:</p>
<pre><code>dotnet new -<span class="hljs-selector-tag">i</span> Microsoft<span class="hljs-selector-class">.AspNetCore</span><span class="hljs-selector-class">.Blazor</span><span class="hljs-selector-class">.Templates</span>
</code></pre>
</li>
</ol>
<p>You can find getting started instructions, docs, and tutorials for Blazor at <a href="https://blazor.net">https://blazor.net</a>.</p>
<h2 id="upgrade-an-existing-project-to-blazor-0-7-0">Upgrade an existing project to Blazor 0.7.0</h2>
<p>To upgrade a Blazor 0.6.0 project to 0.7.0:</p>
<ul>
<li>Install the prerequisites listed above.</li>
<li>
<p>Update the Blazor packages and .NET CLI tool references to 0.7.0. The upgraded Blazor project file should look like this:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Project</span> <span class="hljs-attr">Sdk</span>=<span class="hljs-string">"Microsoft.NET.Sdk.Web"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">PropertyGroup</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">TargetFramework</span>&gt;</span>netstandard2.0<span class="hljs-tag">&lt;/<span class="hljs-name">TargetFramework</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">RunCommand</span>&gt;</span>dotnet<span class="hljs-tag">&lt;/<span class="hljs-name">RunCommand</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">RunArguments</span>&gt;</span>blazor serve<span class="hljs-tag">&lt;/<span class="hljs-name">RunArguments</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">LangVersion</span>&gt;</span>7.3<span class="hljs-tag">&lt;/<span class="hljs-name">LangVersion</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">PropertyGroup</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">ItemGroup</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Microsoft.AspNetCore.Blazor.Browser"</span> <span class="hljs-attr">Version</span>=<span class="hljs-string">"0.7.0"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Microsoft.AspNetCore.Blazor.Build"</span> <span class="hljs-attr">Version</span>=<span class="hljs-string">"0.7.0"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">DotNetCliToolReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Microsoft.AspNetCore.Blazor.Cli"</span> <span class="hljs-attr">Version</span>=<span class="hljs-string">"0.7.0"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ItemGroup</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">Project</span>&gt;</span>
</code></pre>
</li>
</ul>
<p>That’s it! You’re now ready to try out the latest Blazor features.</p>
<h2 id="cascading-values-and-parameters">Cascading values and parameters</h2>
<p>Blazor components can accept parameters that can be used to flow data into a component and impact the component’s rendering. Parameter values are provided from parent component to child component. Sometimes, however, it’s inconvenient to flow data from an ancestor component to a descendent component, especially when there are many layers in between. Cascading values and parameters solve this problem by providing a convenient way for an ancestor component to provide a value that is then available to all descendent components. They also provide a great way for components to coordinate.</p>
<p>For example, if you wanted to provide some theme information for a specific part of your app you could flow the relevant styles and classes from component to component, but this would be tedious and cumbersome. Instead, a common ancestor component can provide the theme information as a cascading value that descendents can accept as a cascading parameter and then consume as needed.</p>
<p>Let’s say the following <code>ThemeInfo</code> class specifies all of the theme information that you want to flow down the component hierarchy so that all of the buttons within that part of your app share the same look and feel:</p>
<pre><code class="lang-csharp"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ThemeInfo</span>
{ <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> ButtonClass { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
}
</code></pre>
<p>An ancestor component can provide a cascading value using the <code>CascadingValue</code> component. The <code>CascadingValue</code> component wraps a subtree of the component hierarchy and specifies a single value that will be available to all components within that subtree. For example, we could specify the theme info in our application layout as a cascading parameter for all components that make up the layout body like this:</p>
<pre><code class="lang-html"><span class="hljs-meta">@inherits</span> <span class="hljs-type">BlazorLayoutComponent</span>

&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"sidebar"</span>&gt; &lt;<span class="hljs-type">NavMenu</span> /&gt;
&lt;/div&gt;

&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"main"</span>&gt; &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"top-row px-4"</span>&gt; &lt;a href=<span class="hljs-string">"http://blazor.net"</span> target=<span class="hljs-string">"_blank"</span> <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"ml-md-auto"</span>&gt;<span class="hljs-type">About</span>&lt;/a&gt; &lt;/div&gt;
&lt;<span class="hljs-type">CascadingValue</span> <span class="hljs-type">Value</span>=<span class="hljs-string">"@theme"</span>&gt; &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"content px-4"</span>&gt; <span class="hljs-meta">@Body</span> &lt;/div&gt; &lt;/<span class="hljs-type">CascadingValue</span>&gt;
&lt;/div&gt;

<span class="hljs-meta">@functions</span> { <span class="hljs-type">ThemeInfo</span> theme = <span class="hljs-keyword">new</span> <span class="hljs-type">ThemeInfo</span> { <span class="hljs-type">ButtonClass</span> = <span class="hljs-string">"btn-success"</span> };
}
</code></pre>
<p>To make use of cascading values, components can declare cascading parameters using the <code>[CascadingParameter]</code> attribute. Cascading values are bound to cascading parameters by type. In the following example the <code>Counter</code> component is modified to have a cascading parameter that binds to the <code>ThemeInfo</code> cascading value, which is then used to set the class for the button.</p>
<pre><code class="lang-html">@page <span class="hljs-string">"/counter"</span>

&lt;h1&gt;Counter&lt;/h1&gt;

&lt;p&gt;Current count: @currentCount&lt;/p&gt;

&lt;button <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn @ThemeInfo.ButtonClass"</span> onclick=<span class="hljs-string">"@IncrementCount"</span>&gt;Click me&lt;/button&gt;

@functions { <span class="hljs-keyword">int</span> currentCount = <span class="hljs-number">0</span>;
[CascadingParameter] <span class="hljs-keyword">protected</span> ThemeInfo ThemeInfo { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">IncrementCount</span>(<span class="hljs-params" />) </span>{ currentCount++; }
}
</code></pre>
<p>When we run the app we can see that the new style is applied:</p>
<p><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/11/blazor-0-7-0-experimental-release-now-available.png" alt="Counter with cascading parameter" /></p>
<p>Cascading parameters also enable components to collaborate across the component hierarchy. For example, let’s say you have a <code>TabSet</code> component that contains a number of <code>Tab</code> components, like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">TabSet</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">Tab</span> <span class="hljs-attr">Title</span>=<span class="hljs-string">"First tab"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>First tab<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span> This is the first tab. <span class="hljs-tag">&lt;/<span class="hljs-name">Tab</span>&gt;</span>
@if (showSecondTab) { <span class="hljs-tag">&lt;<span class="hljs-name">Tab</span> <span class="hljs-attr">Title</span>=<span class="hljs-string">"Second"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>Second tab<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span> You can toggle me. <span class="hljs-tag">&lt;/<span class="hljs-name">Tab</span>&gt;</span> }
<span class="hljs-tag">&lt;<span class="hljs-name">Tab</span> <span class="hljs-attr">Title</span>=<span class="hljs-string">"Third"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>Third tab<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">@showSecondTab</span> /&gt;</span> Toggle second tab <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">Tab</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">TabSet</span>&gt;</span>
</code></pre>
<p>In this example the child <code>Tab</code> components are not explicitly passed as parameters to the <code>TabSet</code>. Instead they are simply part of the child content of the <code>TabSet</code>. But the <code>TabSet</code> still needs to know about each <code>Tab</code> so that it can render the headers and the active tab. To enable this coordination without requiring any specific wire up from the user, the <code>TabSet</code> component can provide <em>itself</em> as a cascading value that can then be picked up by the descendent <code>Tab</code> components:</p>
<p>In <em>TabSet.cshtml</em></p>
<pre><code class="lang-csharp"><span class="hljs-comment">&lt;!-- Display the tab headers --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">CascadingValue</span> <span class="hljs-attr">Value</span>=<span class="hljs-string">this</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav nav-tabs"</span>&gt;</span> @ChildContent <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">CascadingValue</span>&gt;</span>
</code></pre>
<p>This allows the descendent <code>Tab</code> components to capture the containing <code>TabSet</code> as a cascading parameter, so they can add themselves to the <code>TabSet</code> and coordinate on which <code>Tab</code> is active:</p>
<p>In <em>Tab.cshtml</em></p>
<pre><code class="lang-csharp">[CascadingParameter] TabSet ContainerTabSet { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
</code></pre>
<p>Check out the full <code>TabSet</code> sample <a href="https://gist.github.com/SteveSandersonMS/f10a552e1761ff759b1631d81a4428c3">here</a>.</p>
<h2 id="debugging-improvements">Debugging improvements</h2>
<p>In Blazor 0.5.0 we added some very preliminary support for <a href="https://blazor.net/docs/debugging.html">debugging client-side Blazor apps in the browser</a>. While this initial debugging support demonstrated that debugging .NET apps in the browser was possible, it was still a pretty rough experience. Blazor 0.7.0 picks up the latest runtime updates, which includes some fixes that makes the debugging experience more reliable. You can now more reliably set and remove breakpoints, and the reliability of step debugging has been improved.</p>
<p><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/11/blazor-0-7-0-experimental-release-now-available-1.png" alt="Improved Blazor debugging" /></p>
<h2 id="give-feedback">Give feedback</h2>
<p>We hope you enjoy this latest preview release of Blazor. As with previous releases, your feedback is important to us. If you run into issues or have questions while trying out Blazor, <a href="https://github.com/aspnet/blazor/issues">file issues on GitHub</a>. You can also chat with us and the Blazor community on <a href="https://gitter.im/aspnet/blazor">Gitter</a> if you get stuck or to share how Blazor is working for you. After you’ve tried out Blazor for a while please let us know what you think by taking our in-product survey. Click the survey link shown on the app home page when running one of the Blazor project templates:</p>
<p><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/11/blazor-0-7-0-experimental-release-now-available-2.png" alt="Blazor survey" /></p>
<p>Thanks for trying out Blazor!</p>
<p> </p>
</div>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016