Open StevenTCramer opened 1 year ago
The reason why you get such a result is there is no styling for those components. The SplitContainer
is just a container component, so you have to take all responsibility for its appearance, such as size, border color and style, background color, etc.
For example, if you add the CSS styles below to the end of the wwwroot/css/site.css
file:
.split-container {
width: 100%;
height: 320px;
}
.spliter-bar {
background-color: blueviolet;
}
.pane-of-split-container {
display: flex;
justify-content: center;
align-items: center;
border: dashed 2px blueviolet;
}
Then, you will see the result in the following screenshot.
That's all.
dotnet new blazorserver-empty -n SplitterTest
cd .\SplitterTest\
dotnet add package Toolbelt.Blazor.SplitContainer
Change Pages/Index.razor to
@page "/"
@using Toolbelt.Blazor.Splitter
<SplitContainer @bind-FirstPaneSize="_PaneSize">
<FirstPane>
<h1>Hello</h1>
</FirstPane>
<SecondPane>
<h1>World</h1>
</SecondPane>
</SplitContainer>
<style>
.split-container {
width: 100%;
height: 320px;
}
.spliter-bar {
background-color: blueviolet;
}
.pane-of-split-container {
display: flex;
justify-content: center;
align-items: center;
border: dashed 2px blueviolet;
}
</style>
@code {
private int _PaneSize = 80;
}
dotnet run
result looks like
So what does it take if I want to start from empty template?
@StevenTCramer Sorry too late. This package assumes that the application uses Blazor's CSS isolation by default. Usually, this pre-requirement is appropriate. However, unfortunately, Blazor projects made by the "empty" project template are not configured for CSS isolation. Therefore you should include the CSS file of this package by yourself in that scenario.
Specifically, you should include the bundled CSS file for the project, like the following code,
<!DOCTYPE html>
<html lang="en">
<head>
...
<!-- 👇 Add this line. -->
<link href="SplitterTest.styles.css" rel="stylesheet" />
....
or the CSS file for this package individually, like the following code.
<!DOCTYPE html>
<html lang="en">
<head>
...
<!-- 👇 Add this line. -->
<link href="_content/Toolbelt.Blazor.SplitContainer/Toolbelt.Blazor.SplitContainer.bundle.scp.css"
rel="stylesheet" />
...
See also: https://learn.microsoft.com/aspnet/core/blazor/components/css-isolation
Add the following to
_Imports.razor
Change
Pages/Index.razor
toresult looks like