syncfusion/blazor-ui-components-skills / skills/syncfusion-blazor-listview
syncfusion-blazor-listview
VerifiedGuide for implementing Syncfusion Blazor ListView component. Use this when building list-based interfaces with data binding, filtering, grouping, virtual scrolling, selection modes, and custom templates. Covers installation, templating, event handling, and advanced patterns.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.4 KB |
| references/advanced-layouts.md | markdown | 23.0 KB |
| references/advanced-patterns.md | markdown | 12.6 KB |
| references/api-reference.md | markdown | 23.9 KB |
| references/data-binding-and-source.md | markdown | 10.6 KB |
| references/events-and-navigation.md | markdown | 9.3 KB |
| references/filtering-and-searching.md | markdown | 9.4 KB |
| references/getting-started.md | markdown | 6.0 KB |
| references/grouping-and-organization.md | markdown | 12.7 KB |
| references/item-selection-and-actions.md | markdown | 11.3 KB |
| references/styling-and-customization.md | markdown | 8.5 KB |
| references/templating-and-rendering.md | markdown | 9.6 KB |
| references/virtualization-and-performance.md | markdown | 8.1 KB |
references/events-and-navigation.md
View on GitHub# Events and Navigation in Blazor ListView
## Table of Contents
- [Event Handling](#event-handling)
- [ListViewItem Events](#listviewitem-events)
- [Navigation Patterns](#navigation-patterns)
- [Hyperlink Integration](#hyperlink-integration)
- [Complete Event Example](#complete-event-example)
## Event Handling
### Available Events
The ListView provides lifecycle and interaction events:
```cshtml
<ListViewEvents TValue="Item"
OnActionBegin="@OnActionBegin"
OnActionComplete="@OnActionComplete"
Clicked="@OnClicked">
</ListViewEvents>
@code {
void OnActionBegin(ActionBeginEventArgs<Item> args)
{
// Triggered when action starts
// args.EventType, args.Data available
}
void OnActionComplete(ActionCompleteEventArgs<Item> args)
{
// Triggered when action completes
// Data binding complete event
}
void OnClicked(ClickEventArgs<Item> args)
{
// Triggered when item is clicked
// args.Text, args.Data available
}
}
```
### Event Flow
```
User Action → OnActionBegin → Processing → OnActionComplete
↓
Event Completion
```
## ListViewItem Events
### Click Event
```cshtml
@using Syncfusion.Blazor.Lists
<SfListView DataSource="@Items">
<ListViewFieldSettings TValue="Item" Id="Id" Text="Text"></ListViewFieldSettings>
<ListViewEvents TValue="Item"
Clicked="@(e => OnItemClicked(e))">
</ListViewEvents>
</SfListView>
<p>Clicked Item: @SelectedItemText</p>
@code {
string SelectedItemText = "";
void OnItemClicked(ClickEventArgs<Item> args)
{
SelectedItemText = args.Text;
Console.WriteLine($"Item clicked: {args.Text}");
// Access item data
var itemData = args.Data;
}
List<Item> Items = new List<Item>
{
new Item { Id = "1", Text = "Option 1" },
new Item { Id = "2", Text = "Option 2" }
};
public class Item
{
public string Id { get; set; }
public string Text { get; set; }
}
}
```
### ActionBegin Event - Data Binding
```csharp
void OnActionBegin(ActionBeginEventArgs<Item> args)
{
// Triggered when ListView starts binding data
if (args.EventType == "initially")
{
Console.WriteLine("ListView initializing...");
}
}
```
### ActionComplete Event - Data Binding Complete
```csharp
void OnActionComplete(ActionCompleteEventArgs<Item> args)
{
// Triggered when data binding completes
Console.WriteLine($"Data bound successfully. Total items: {args.Result?.Count}");
}
```
## Navigation Patterns
### Navigate on Item Click
```cshtml
@using Syncfusion.Blazor.Lists
@inject NavigationManager NavigationManager
<SfListView DataSource="@Pages">
<ListViewFieldSettings TValue="Page" Id="Id" Text="Name"></ListViewFieldSettings>
<ListViewEvents TValue="Page"
Clicked="@(e => Navigate(e.Data.Url))">
</ListViewEvents>
</SfListView>
@code {
void Navigate(string url)
{
NavigationManager.NavigateTo(url);
}
List<Page> Pages = new List<Page>
{
new Page { Id = "1", Name = "Home", Url = "/" },
new Page { Id = "2", Name = "About", Url = "/about" },
new Page { Id = "3", Name = "Contact", Url = "/contact" }
};
public class Page
{
public string Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
}
}
```
### Detail View Navigation
```csharp
void OnItemClicked(ClickEventArgs<Product> args)
{
var productId = args.Data.Id;
NavigationManager.NavigateTo($"/product-details/{productId}");
}
```
## Hyperlink Integration
### Using Anchor Tags in Templates
```cshtml
@using Syncfusion.Blazor.Lists
<SfListView DataSource="@DataSource">
<ListViewFieldSettings TValue="ListDataModel" Id="Id" Text="Name"></ListViewFieldSettings>
<ListViewTemplates TValue="ListDataModel">
<Template>
<a target="_blank" href="@((context as ListDataModel).Url)">
@((context as ListDataModel).Name)
</a>
</Template>
</ListViewTemplates>
</SfListView>
@code {
List<ListDataModel> DataSource = new List<ListDataModel>
{
new ListDataModel { Id = "1", Name = "Google", Url = "url" },
new ListDataModel { Id = "2", Name = "Bing", Url = "url" },
new ListDataModel { Id = "3", Name = "Yahoo", Url = "url" },
new ListDataModel { Id = "4", Name = "Ask.com", Url = "url" }
};
public class ListDataModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
}
}
```
### Blazor Navigation Links
```cshtml
@using Syncfusion.Blazor.Lists
<SfListView DataSource="@Users" CssClass="e-list-template">
<ListViewFieldSettings TValue="User" Id="Id" Text="Name"></ListViewFieldSettings>
<ListViewTemplates TValue="User">
<Template>
<NavLink href="@($"/user/{((context as User).Id}")">
<div class="e-list-wrapper">
<span class="e-list-content">@((context as User).Name)</span>
</div>
</NavLink>
</Template>
</ListViewTemplates>
</SfListView>
@code {
List<User> Users = new List<User>
{
new User { Id = "1", Name = "User A" },
new User { Id = "2", Name = "User B" }
};
public class User
{
public string Id { get; set; }
public string Name { get; set; }
}
}
```
### Combined Navigation and Event Handling
```csharp
void OnItemClicked(ClickEventArgs<MenuItem> args)
{
// Custom logic
LogUserAction(args.Data.Name);
// Navigate
if (!string.IsNullOrEmpty(args.Data.NavigateUrl))
{
NavigationManager.NavigateTo(args.Data.NavigateUrl);
}
}
void LogUserAction(string itemName)
{
Console.WriteLine($"User selected: {itemName}");
// Send to analytics, etc.
}
```
## Complete Event Example
```cshtml
@using Syncfusion.Blazor.Lists
@inject NavigationManager NavigationManager
<div>
<SfListView @ref="ListView"
DataSource="@Items"
ShowHeader="true"
HeaderTitle="Event Demo">
<ListViewFieldSettings TValue="MenuItem" Id="Id" Text="Name"></ListViewFieldSettings>
<ListViewTemplates TValue="MenuItem">
<Template>
<div class="e-list-wrapper" @onclick="@((e) => OnItemClicked((context as MenuItem)))">
<span class="e-list-content">@((context as MenuItem).Name)</span>
</div>
</Template>
</ListViewTemplates>
<ListViewEvents TValue="MenuItem"
OnActionBegin="@OnActionBegin"
OnActionComplete="@OnActionComplete"
Clicked="@OnEventClicked">
</ListViewEvents>
</SfListView>
<!-- Event Log -->
<div style="margin-top: 20px; padding: 12px; background-color: #f5f5f5; border: 1px solid #ddd;">
<h4>Event Log:</h4>
<ul style="list-style: none; padding: 0;">
@foreach (var log in EventLog)
{
<li style="padding: 4px 0; font-size: 12px;">
<span style="color: #999;">[@log.Timestamp]</span> @log.Message
</li>
}
</ul>
</div>
</div>
@code {
SfListView<MenuItem> ListView;
List<MenuItem> Items = new List<MenuItem>();
List<EventLogEntry> EventLog = new List<EventLogEntry>();
private int maxLogs = 10;
protected override void OnInitialized()
{
Items.Add(new MenuItem { Id = "1", Name = "Home", NavigateUrl = "/" });
Items.Add(new MenuItem { Id = "2", Name = "Products", NavigateUrl = "/products" });
Items.Add(new MenuItem { Id = "3", Name = "About", NavigateUrl = "/about" });
Items.Add(new MenuItem { Id = "4", Name = "Contact", NavigateUrl = "/contact" });
}
void OnActionBegin(ActionBeginEventArgs<MenuItem> args)
{
LogEvent("OnActionBegin triggered");
}
void OnActionComplete(ActionCompleteEventArgs<MenuItem> args)
{
LogEvent($"OnActionComplete - Items bound: {Items.Count}");
}
void OnEventClicked(ClickEventArgs<MenuItem> args)
{
LogEvent($"Item clicked: {args.Text}");
}
void OnItemClicked(MenuItem item)
{
LogEvent($"Custom click: {item.Name}");
if (!string.IsNullOrEmpty(item.NavigateUrl))
{
NavigationManager.NavigateTo(item.NavigateUrl);
}
}
void LogEvent(string message)
{
EventLog.Insert(0, new EventLogEntry
{
Timestamp = DateTime.Now.ToString("HH:mm:ss"),
Message = message
});
if (EventLog.Count > maxLogs)
{
EventLog.RemoveAt(EventLog.Count - 1);
}
}
public class MenuItem
{
public string Id { get; set; }
public string Name { get; set; }
public string NavigateUrl { get; set; }
}
public class EventLogEntry
{
public string Timestamp { get; set; }
public string Message { get; set; }
}
}
```
---
**Related Topics:**
- [Item Selection and Actions](item-selection-and-actions.md) - Handle selections
- [Advanced Patterns](advanced-patterns.md) - Complex event scenarios
- [Templating and Rendering](templating-and-rendering.md) - Event-aware templates
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |