PhotoSwipe.Blazor 1.7.0

dotnet add package PhotoSwipe.Blazor --version 1.7.0
                    
NuGet\Install-Package PhotoSwipe.Blazor -Version 1.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PhotoSwipe.Blazor" Version="1.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PhotoSwipe.Blazor" Version="1.7.0" />
                    
Directory.Packages.props
<PackageReference Include="PhotoSwipe.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PhotoSwipe.Blazor --version 1.7.0
                    
#r "nuget: PhotoSwipe.Blazor, 1.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PhotoSwipe.Blazor@1.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PhotoSwipe.Blazor&version=1.7.0
                    
Install as a Cake Addin
#tool nuget:?package=PhotoSwipe.Blazor&version=1.7.0
                    
Install as a Cake Tool

PhotoSwipe.Blazor

A comprehensive Blazor component library that wraps PhotoSwipe and extends it with upload capabilities, image processing, and enhanced gallery management features.

Features

Core Features

  • 🖼️ Responsive image galleries with lightbox
  • ⚡ Lightweight and fast performance
  • 📱 Mobile-friendly with touch support
  • 🎨 Customizable styling with CSS isolation
  • 🔧 Strongly-typed configuration
  • 🎯 Event handling support
  • ♿ Accessibility features

Extended Features

  • 📤 Drag & drop file uploads
  • 🖼️ Client-side image processing and resizing
  • ✅ File validation (size, type)
  • 👁️ Upload preview before confirmation
  • 🔄 Add or replace gallery modes
  • 📊 Upload progress indicators
  • ⚠️ Comprehensive error handling

Requirements

  • .NET 8.0 or .NET 9.0
  • Blazor Server or Blazor WebAssembly

Installation

Add the package reference to your Blazor project:

<PackageReference Include="PhotoSwipe.Blazor" Version="1.0.0" />

Register the services in your Program.cs:

builder.Services.AddPhotoSwipeBlazor();

Include the CSS in your _Layout.cshtml (Blazor Server) or index.html (Blazor WebAssembly):

<link href="_content/PhotoSwipe.Blazor/css/photoswipe.css" rel="stylesheet" />

Usage

@using PhotoSwipe.Blazor.Components
@using PhotoSwipe.Blazor.Models

<PhotoSwipeGallery Items="@images" />

@code {
    private List<PhotoSwipeItem> images = new()
    {
        new PhotoSwipeItem
        {
            Src = "/images/photo1.jpg",
            ThumbnailUrl = "/images/thumb1.jpg",
            Width = 1024,
            Height = 768,
            Alt = "Beautiful landscape"
        },
        new PhotoSwipeItem
        {
            Src = "/images/photo2.jpg",
            ThumbnailUrl = "/images/thumb2.jpg",
            Width = 800,
            Height = 600,
            Alt = "City skyline"
        }
    };
}
<PhotoSwipeGallery Items="@images">
    <ItemTemplate Context="item">
        <div class="custom-thumbnail">
            <img src="@item.ThumbnailUrl" alt="@item.Alt" />
            <div class="overlay">
                <h4>@item.Title</h4>
                <p>@item.Caption</p>
            </div>
        </div>
    </ItemTemplate>
</PhotoSwipeGallery>
<PhotoSwipeLightbox Items="@images">
    <TriggerTemplate Context="item">
        <button class="custom-trigger">
            <img src="@item.ThumbnailUrl" alt="@item.Alt" />
            <span>View @item.Title</span>
        </button>
    </TriggerTemplate>
</PhotoSwipeLightbox>

Configuration Options

<PhotoSwipeGallery Items="@images" Options="@options" />

@code {
    private PhotoSwipeOptions options = new()
    {
        ShowHideAnimationType = "fade",
        ShowAnimationDuration = 500,
        BackgroundOpacity = 0.9,
        Loop = true,
        WheelToZoom = true,
        MaxZoomLevel = 3.0
    };
}

Event Handling

<PhotoSwipeGallery Items="@images" 
                   OnOpen="OnGalleryOpen" 
                   OnClose="OnGalleryClose" 
                   OnChange="OnImageChange" />

@code {
    private void OnGalleryOpen(PhotoSwipeEventArgs args)
    {
        Console.WriteLine($"Gallery opened at index {args.Event.Index}");
    }

    private void OnGalleryClose(PhotoSwipeEventArgs args)
    {
        Console.WriteLine("Gallery closed");
    }

    private void OnImageChange(PhotoSwipeEventArgs args)
    {
        Console.WriteLine($"Changed to image {args.Event.Index}");
    }
}

PhotoSwipeItem Properties

Property Type Description
Src string Full-size image URL
ThumbnailUrl string? Thumbnail image URL (optional)
Width int Image width in pixels
Height int Image height in pixels
Alt string? Alt text for accessibility
Caption string? Image caption
Title string? Image title
ThumbnailClass string? CSS class for thumbnail
Data object? Custom data object

PhotoSwipeOptions

The PhotoSwipeOptions class provides strongly-typed access to all PhotoSwipe configuration options:

  • Animation: ShowHideAnimationType, ShowAnimationDuration, HideAnimationDuration
  • Appearance: BackgroundOpacity, Spacing
  • Interaction: AllowPanToNext, Loop, PinchToClose, WheelToZoom
  • Zoom: MaxZoomLevel, InitialZoomLevel, SecondaryZoomLevel
  • Accessibility: EscKey, ArrowKeys, ReturnFocus, TrapFocus
  • UI: Counter, CloseTitle, ZoomTitle, ErrorMessage

CSS Customization

The components use CSS isolation, but you can override styles globally:

.photoswipe-gallery {
    gap: 20px;
    padding: 20px;
}

.photoswipe-item {
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.photoswipe-item:hover {
    transform: scale(1.02);
}

PhotoSwipeUploadGallery Component

The PhotoSwipeUploadGallery extends the base gallery with comprehensive upload functionality:

@using PhotoSwipe.Blazor.Components
@using PhotoSwipe.Blazor.Models

<PhotoSwipeUploadGallery 
    Items="@images"
    MaxFileSize="@(10 * 1024 * 1024)"  // 10MB limit
    MaxFiles="20"
    AllowMultiSelect="true"
    OnItemsChanged="@OnGalleryChanged"
    OnItemsUploaded="@OnItemsUploaded" />

@code {
    private List<PhotoSwipeItem> images = new();
    
    private void OnGalleryChanged(IEnumerable<PhotoSwipeItem> items)
    {
        images = items.ToList();
        StateHasChanged();
    }
    
    private void OnItemsUploaded(IEnumerable<PhotoSwipeItem> uploadedItems)
    {
        Console.WriteLine($"Uploaded {uploadedItems.Count()} new images");
    }
}
<PhotoSwipeUploadGallery 
    Items="@images"
    UploadMode="PhotoSwipeUploadMode.Add"
    MaxFileSize="@(15 * 1024 * 1024)">
    <ItemTemplate Context="item">
        <div class="custom-upload-item">
            <img src="@item.ThumbnailUrl" alt="@item.Alt" />
            <div class="overlay">
                <span>@item.Title</span>
                <span>@($"{item.Width}×{item.Height}")</span>
            </div>
        </div>
    </ItemTemplate>
</PhotoSwipeUploadGallery>
Property Type Description
Items IEnumerable<PhotoSwipeItem> Current gallery items
UploadMode PhotoSwipeUploadMode Add or Replace mode
MaxFileSize long Maximum file size in bytes (default: 10MB)
MaxFiles int Maximum number of files per upload (default: 20)
AllowMultipleFiles bool Enable multiple file selection (default: true)
AllowAdd bool Enable upload functionality (default: true)
AllowDelete bool Enable delete functionality (default: false)
EnableSelection bool Enable item selection (default: false)
AllowMultiSelect bool Enable multiple item selection (default: true)
SelectedItem PhotoSwipeItem? Currently selected single item
SelectedItems IEnumerable<PhotoSwipeItem>? Currently selected multiple items
CustomOverlayControls RenderFragment<PhotoSwipeItem>? Custom overlay controls template
Event Type Description
OnOpen EventCallback<PhotoSwipeEventArgs> Fired when lightbox opens
OnClose EventCallback<PhotoSwipeEventArgs> Fired when lightbox closes
OnChange EventCallback<PhotoSwipeEventArgs> Fired when lightbox slide changes
OnItemsChanged EventCallback<IEnumerable<PhotoSwipeItem>> Fired when gallery items change
OnItemsUploaded EventCallback<IEnumerable<PhotoSwipeItem>> Fired after successful upload
OnItemDeleted EventCallback<PhotoSwipeItem> Fired when single item is deleted
OnItemsDeleted EventCallback<IEnumerable<PhotoSwipeItem>> Fired when multiple items are deleted
SelectedItemChanged EventCallback<PhotoSwipeItem> Fired when single selection changes
SelectedItemsChanged EventCallback<IEnumerable<PhotoSwipeItem>> Fired when multiple selection changes

Advanced Usage

Programmatic Control

<PhotoSwipeGallery @ref="galleryRef" Items="@images" />
<button @onclick="() => galleryRef?.OpenAsync(2)">Open at index 2</button>

@code {
    private PhotoSwipeGallery? galleryRef;
}

Dynamic Updates

<PhotoSwipeGallery Items="@images" />
<button @onclick="AddImage">Add Image</button>

@code {
    private void AddImage()
    {
        images.Add(new PhotoSwipeItem
        {
            Src = $"/images/photo{images.Count + 1}.jpg",
            Width = 800,
            Height = 600,
            Alt = $"Photo {images.Count + 1}"
        });
        StateHasChanged();
    }
}

Upload Mode Control

<PhotoSwipeUploadGallery 
    Items="@images"
    UploadMode="@currentMode"
    OnItemsChanged="@OnGalleryChanged">
</PhotoSwipeUploadGallery>

<div class="mode-selector">
    <label>
        <input type="radio" checked="@(currentMode == PhotoSwipeUploadMode.Add)" 
               @onchange="@(() => currentMode = PhotoSwipeUploadMode.Add)" />
        Add to Gallery
    </label>
    <label>
        <input type="radio" checked="@(currentMode == PhotoSwipeUploadMode.Replace)" 
               @onchange="@(() => currentMode = PhotoSwipeUploadMode.Replace)" />
        Replace Gallery
    </label>
</div>

@code {
    private PhotoSwipeUploadMode currentMode = PhotoSwipeUploadMode.Add;
}

License

This project is licensed under the MIT License. PhotoSwipe is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.7.0 82 2/25/2026
1.6.0 225 9/30/2025
1.5.0 198 9/30/2025
1.4.0 199 9/29/2025
1.3.0 206 9/24/2025
1.2.0 203 9/23/2025
1.1.4 197 9/23/2025
1.1.3 208 9/23/2025
1.1.2 196 9/23/2025
1.1.1 203 9/23/2025
1.1.0 194 9/23/2025
1.0.1 222 9/22/2025
1.0.0 230 9/22/2025