Skip to content

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

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;
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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