Interaction & Behavior

This feature set governs how users interact with the chip control, including selection, grouping, and the handling of a close button for chip removal.

Overview

The Interaction & Behavior feature controls the chip's interactive elements and state management. It allows developers to enable or disable selection, assign chips to mutually exclusive groups, and determine whether a close button is displayed that triggers disposal events. This feature enhances user experience by providing immediate visual and event-based feedback on interactions. The primary properties and events in this feature are:

Property
Description
Default Value
Valid Range / Notes

ShowCloseButton

Determines whether a close (X) button is displayed on the chip. When clicked, it triggers the CloseClicked event.

false

Boolean; set to true to display the close button.

EnableSelection

Enables or disables the ability to select the chip.

true

Boolean; when false, the chip will not enter a selected state.

IsSelected

Indicates the current selection state of the chip, applying corresponding visual cues when true.

false

Boolean; state toggles on click if EnableSelection is true.

Group

Assigns the chip to a group so that only one chip within the group can be selected at a time.

string.Empty

String; when assigned, changing selection on one chip automatically deselects others in the same group.

AutoDisposeOnClose

When true, the chip automatically disposes itself after the close button is clicked.

true

Boolean; set to false if manual disposal is preferred.

Event
Description

ChipClicked

Raised when the chip (excluding the close button) is clicked.

CloseClicked

Raised when the close button is clicked.

SelectionChanged

Raised when the chip’s selected state changes.

StateChanged

Raised when key appearance or state properties change (e.g., IsSelected, EnableSelection, Group, etc.).

Key Points

Aspect
Details

Interactive Feedback

Provides clear events and visual state changes (selection, closing) to inform users of their actions.

Group Management

Grouping chips allows for mutually exclusive selection, which is ideal for filter selections or options.

Automated Disposal

The AutoDisposeOnClose property simplifies resource management by automatically removing chips on close.

Best Practices

Practice
Recommendation

Use Grouping for Clarity

Assign chips to groups when you want only one chip to be selected at a time to avoid user confusion.

Manage Selection State

Always check and update the IsSelected property appropriately, and subscribe to SelectionChanged to update related UI parts.

Dispose of Resources Wisely

Use AutoDisposeOnClose to automate cleanup, but ensure that manual disposal is handled if further actions are needed after closing.

Common Pitfalls

Pitfall
Explanation

Overlooking Group Management

Failing to set the Group property when using multiple selectable chips may lead to multiple chips being selected simultaneously.

Ignoring Selection Enablement

Forgetting to disable EnableSelection when needed might lead to unexpected selection behavior.

Unmanaged Disposal

Not properly handling chip disposal (either via AutoDisposeOnClose or manual disposal) may result in memory leaks.

Usage Scenarios

Scenario
Description

Filter Selection

In a search or filter interface, chips can be grouped so that only one filter option is active at any time.

Tag or Category Management

Chips representing tags can be selectable; clicking a tag toggles its selected state and triggers related events.

Removable Items

Use the close button on chips in scenarios such as removing user-selected items from a list, with immediate visual feedback.

Real Life Usage Scenarios

Scenario
Real Life Example

Email Client Labels

In an email client, chips can represent labels that users can select to filter their inbox, and they may remove labels by clicking the close button.

E-Commerce Product Filters

A shopping app might use chips to allow users to select one product category at a time, ensuring only one filter is active.

Dashboard Widget Management

Users can manage active dashboard widgets by selecting or closing chips that represent each widget, simplifying the user interface.

Troubleshooting Tips

Tip
Recommendation

Check Event Subscriptions

Ensure that ChipClicked, CloseClicked, and SelectionChanged events are properly subscribed to for intended UI updates.

Validate Group Behavior

When using the Group property, test to ensure that only one chip per group is selected at a time, and that state changes propagate correctly.

Monitor Disposal Processes

If using AutoDisposeOnClose, verify that the chip is removed from the parent control and disposed without error.

Code Examples

Basic Interaction Integration

The following example demonstrates how to create a chip that supports selection and a close button, along with handling the respective events:

using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

public class InteractionDemoForm : Form
{
    private SiticoneChip chip;

    public InteractionDemoForm()
    {
        this.Text = "Chip Interaction Demo";
        this.Size = new Size(400, 300);
        InitializeChip();
    }

    private void InitializeChip()
    {
        chip = new SiticoneChip
        {
            Text = "Selectable Chip",
            Location = new Point(50, 50),
            Size = new Size(250, 40),
            // Interaction & Behavior settings
            EnableSelection = true,
            IsSelected = false,
            ShowCloseButton = true,
            AutoDisposeOnClose = true,
            // Optional grouping
            Group = "DemoGroup"
        };

        // Event subscriptions
        chip.ChipClicked += (s, e) =>
        {
            MessageBox.Show("Chip was clicked!");
        };

        chip.CloseClicked += (s, e) =>
        {
            MessageBox.Show("Close button was clicked, chip will be disposed.");
        };

        chip.SelectionChanged += (s, e) =>
        {
            var selectedChip = s as SiticoneChip;
            MessageBox.Show($"{selectedChip.Text} selected state is now: {selectedChip.IsSelected}");
        };

        this.Controls.Add(chip);
    }

    [STAThread]
    public static void Main()
    {
        Application.Run(new InteractionDemoForm());
    }
}

Grouped Chips for Exclusive Selection

The following example illustrates how to group multiple chips so that only one can be selected at a time:

using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

public class GroupedChipsDemoForm : Form
{
    public GroupedChipsDemoForm()
    {
        this.Text = "Grouped Chips Demo";
        this.Size = new Size(500, 350);
        InitializeChips();
    }

    private void InitializeChips()
    {
        string groupName = "FilterGroup";
        int baseY = 50;

        for (int i = 0; i < 3; i++)
        {
            var chip = new SiticoneChip
            {
                Text = $"Option {i + 1}",
                Group = groupName,
                Location = new Point(50, baseY + (i * 60)),
                Size = new Size(300, 40),
                // Interaction & Behavior settings
                EnableSelection = true,
                ShowCloseButton = false
            };

            chip.SelectionChanged += (s, e) =>
            {
                var currentChip = s as SiticoneChip;
                // Only one chip in the group should be selected at a time.
                Console.WriteLine($"{currentChip.Text} selected: {currentChip.IsSelected}");
            };

            this.Controls.Add(chip);
        }
    }

    [STAThread]
    public static void Main()
    {
        Application.Run(new GroupedChipsDemoForm());
    }
}

Review

Aspect
Review Comments

User Interactivity

The feature set effectively provides event-based feedback and clear selection behavior for enhanced user engagement.

Flexibility

Developers can easily toggle selection, manage groups, and incorporate a close button to suit varied application needs.

Resource Management

AutoDisposeOnClose offers a convenient means of handling chip disposal, though careful testing is advised to avoid premature disposal.

Summary

The Interaction & Behavior feature of the SiticoneChip control empowers developers to build interactive and responsive chip elements. By enabling selection, grouping chips for exclusive selection, and providing a close button with automatic disposal options, this feature set delivers robust user interaction mechanisms. Proper event handling and property management ensure that chips respond accurately to user actions, enhancing the overall user experience.

Additional Useful Sections

Integration Checklist

Checklist Item
Status/Recommendation

Verify Event Handlers

Confirm that ChipClicked, CloseClicked, and SelectionChanged events are properly implemented.

Test Grouping Functionality

Ensure that when chips share a Group value, only one chip remains selected at any time.

Validate Disposal Behavior

Check that AutoDisposeOnClose correctly removes and disposes of chips from the parent control.

Demo Tips

Tip
Description

Interactive Testing

Implement a test harness where developers can toggle EnableSelection and ShowCloseButton at runtime to observe behavior.

Group Demonstration

Showcase grouped chips with exclusive selection to highlight the use of the Group property in real-world scenarios.

Event Logging

Use console or UI logging to display event triggers (e.g., SelectionChanged) to assist in debugging and verification.

This extensive documentation should assist developers in integrating and customizing the Interaction & Behavior feature of the SiticoneChip control, ensuring that chip interactions are both intuitive and responsive within their applications.

Last updated