Skip to content

How-to-show-the-filter-status-message-in-wpf-datagrid breaks if used in more than one SfDataGrid #67

Open
@CADbloke

Description

@CADbloke

it throws a System.Windows.Markup.XamlParseException - System.ArgumentException: PropertyMetadata is already registered for type 'FilterStatusBar' at the ctor

at https://github.com/SyncfusionExamples/WPF-DataGrid-Samples/blob/main/How-to-show-the-filter-status-message-in-wpf-datagrid/WPF/CS/StatusBar/FilterStatusBar.cs#L91

I replaced

/// <summary>
/// Initializes the <see cref="FilterStatusBar"/> class.
/// </summary>
public FilterStatusBar()
{
    DefaultStyleKeyProperty.OverrideMetadata(typeof(FilterStatusBar), new FrameworkPropertyMetadata(typeof(FilterStatusBar)));          
}

with

private static bool alreadyRegistered = false;

/// <summary>
/// Initializes the <see cref="FilterStatusBar"/> class.
/// </summary>
public FilterStatusBar()
{
    if (!alreadyRegistered)      
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(FilterStatusBar), new FrameworkPropertyMetadata(typeof(FilterStatusBar)));
        alreadyRegistered = true;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions