Back to Devexpress

DxFileInput.Visible Property

blazor-devexpress-dot-blazor-dot-dxfileinput-9309cc76.md

latest3.5 KB
Original Source

DxFileInput.Visible Property

Specifies whether the component is visible.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[DefaultValue(true)]
[Parameter]
public bool Visible { get; set; }

Property Value

TypeDefaultDescription
Booleantrue

true to display the component; otherwise, false.

|

Remarks

Disable the Visible property to hide the File Input component. You can disable the ShowSelectButton or ShowFileList property to hide only the select button or the file list.

The following example implements an external select button and a drop zone container for the File Input component. The component is hidden when its file list is empty.

razor
<div id="overviewDemoDropZone" class="card custom-drop-zone bg-light rounded-3 w-100 m-0">
    <span class="drop-file-icon mb-3"></span>
    <span>Drag and Drop File Here</span><span class="m-1">or</span>
    <button id="overviewDemoSelectButton" class="btn border-primary btn-primary m-1">Select File</button>
</div>

<DxFileInput Visible="FileInputVisible" 
             FilesUploading="OnFilesUploading"
             SelectedFilesChanged="SelectedFilesChanged"
             ExternalSelectButtonCssSelector="#overviewDemoSelectButton"
             ExternalDropZoneCssSelector="#overviewDemoDropZone"
             ExternalDropZoneDragOverCssClass="bg-light border-secondary text-dark" />

@code {
    bool FileInputVisible { get; set; } = false;

    protected void SelectedFilesChanged(IEnumerable<UploadFileInfo> files) {
        FileInputVisible = files.ToList().Count > 0;
        InvokeAsync(StateHasChanged);
    }
    async Task OnFilesUploading(FilesUploadingEventArgs args) {
        foreach (var file in args.Files) {
            /* The following code is intended for demonstration purposes only.
            Do not read a stream directly in memory to avoid performance and security-related issues. */
            using var stream = new System.IO.MemoryStream();
            await file.OpenReadStream(file.Size).CopyToAsync(stream);
        }
    }
}
css
.custom-drop-zone {
    padding: 0 !important;
    border-style: dashed !important;
    border-width: 2px !important;
    height: 230px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.custom-drop-zone svg {
    width: 42px;
    height: 42px;
}
.drop-file-icon {
    background-size: contain;
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
    background-position: center center;
    background-color: currentColor;
    width: 48px;
    height: 48px;
    -webkit-mask-image: url("../images/icons/drop-file.svg");
    mask-image: url("../images/icons/drop-file.svg");
}

Run Demo: File Input - Overview

See Also

DxFileInput Class

DxFileInput Members

DevExpress.Blazor Namespace