Class Chessboard
Blazor Component for adding an interactive chessboard to a Blazor application. It was build as a Blazor version of chessboard.js and allows to use this functionality without the need to interop with javascript.
There are however quite some differences:
- No animations
- It has chess knowledge and therefore provides legal move check out of the box
Inheritance
Inherited Members
Namespace: PonzianiComponents
Assembly: PonzianiComponents.dll
Syntax
public class Chessboard
Properties
| Improve this Doc View SourceColorDarkSquares
Color of dark squares
Declaration
[Parameter]
public string ColorDarkSquares { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ColorHighlight
Color used for highlighting squares
Declaration
[Parameter]
public string ColorHighlight { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ColorLightSquares
Color of light squares
Declaration
[Parameter]
public string ColorLightSquares { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Fen
Position displayed on the board in Forsyth-Edwards-Notation
Declaration
[Parameter]
public string Fen { get; set; }
Property Value
Type | Description |
---|---|
System.String |
HighlightLastAppliedMove
If true, the squares of the last applied Move get highlighted
Declaration
[Parameter]
public bool HighlightLastAppliedMove { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Id
Id of the rendered HTML element
Declaration
[Parameter]
public string Id { get; set; }
Property Value
Type | Description |
---|---|
System.String |
OnMovePlayed
Is called whenever the user played a move on the board. Only active if SetupMode is false.
Declaration
[Parameter]
public EventCallback<MovePlayedInfo> OnMovePlayed { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.EventCallback<MovePlayedInfo> |
OnSetupChanged
Is called whenever the user changed the board's setup be moving, adding or removing a piece in SetupMode
Declaration
[Parameter]
public EventCallback<SetupChangedInfo> OnSetupChanged { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.EventCallback<SetupChangedInfo> |
OtherAttributes
Other HTML Attributes, which are applied to the root element of the rendered scoresheet.
Declaration
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> OtherAttributes { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Object> |
PathPieceImages
Allowing to replace the current piece images with a different set. The piece images must follow the naming convention {color}{piecetype}.png, so wB.png for white Bishop, bP.png for black Pawn
Declaration
[Parameter]
public string PathPieceImages { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Rotate
If true the board's orientation is reversed
Declaration
[Parameter]
public bool Rotate { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SetupMode
SetupMode can be used to allow the user to set up a new position. If SetupMode is active pieces can be freely moved, added and removed. There are spare pieces shown outside the board. If SetupMode isn't active only legal moves can be played. Default is false.
Declaration
[Parameter]
public bool SetupMode { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ShowCoordinates
If true, the file and rank labels are displayed
Declaration
[Parameter]
public bool ShowCoordinates { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Size
Size (in pixels) of Chessboard
Declaration
[Parameter]
public int Size { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceApplyMove(Move)
Applies a move to the current board
Declaration
public bool ApplyMove(Move move)
Parameters
Type | Name | Description |
---|---|---|
Move | move | The move which shall be applied |
Returns
Type | Description |
---|---|
System.Boolean | true, if move could be applied |
ClearHighlighting()
Removes all square highlights which have been sett by SetHighlightSquare(Square, Boolean)
Declaration
public void ClearHighlighting()
ExitSetupMode()
Leave setup mode (API-call to set parameter SetupMode to false)
Declaration
public void ExitSetupMode()
IsHighlighted(Square)
Checks if a square is highlighted (marked) or not
Declaration
public bool IsHighlighted(Square s)
Parameters
Type | Name | Description |
---|---|---|
Square | s | Square |
Returns
Type | Description |
---|---|
System.Boolean | true if highlighted |
OnAfterRenderAsync(Boolean)
Declaration
protected override async Task OnAfterRenderAsync(bool firstRender)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | firstRender |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
SetFen(String)
API call to set the position
Declaration
public void SetFen(string fen)
Parameters
Type | Name | Description |
---|---|---|
System.String | fen | The new position in FEN-Notation |
SetHighlightSquare(Square, Boolean)
Method to mark/highlight a square
Declaration
public void SetHighlightSquare(Square s, bool highlight = true)
Parameters
Type | Name | Description |
---|---|---|
Square | s | The square, which shall be highlighted |
System.Boolean | highlight | if true, square will be highlighted, if false highlight is switched off |
SwitchToSetupMode()
Enter setup mode (API-call to set parameter SetupMode to true)
Declaration
public void SwitchToSetupMode()