Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:29:18+00:00 2026-05-22T14:29:18+00:00

In WPF, I’ve created 3 UserControls User Configuration, System Configuration & Account Configuration. All

  • 0

In WPF, I’ve created 3 UserControls “User Configuration”, “System Configuration” & “Account Configuration”. All these user controls have “Save” & “Cancel” buttons. On click of these buttons they raise a Routed Event declared and defined in their respective classes. On clicking the Save button “ConfigurationSaved” event is raised & on Cancel button “ConfigurationCancelled” event is raised.

These events when raised, the container which hosts the user control will take care of saving the configuration.

Code Snippet for all the class’s routed event definition is as follows:

AccountConfigurationView:

public partial class AccountConfigurationView : UserControl
{
    static AccountConfigurationView()
    {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent("ConfigurationSaved",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AccountConfigurationView));

        ConfigurationClosedEvent = EventManager.RegisterRoutedEvent("ConfigurationClosed",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AccountConfigurationView));
    }

    #region ROUTED_EVENTS_RELATED
    public static readonly RoutedEvent ConfigurationSavedEvent;
    public static readonly RoutedEvent ConfigurationClosedEvent;

    public event RoutedEventHandler ConfigurationSaved
    {
        add { AddHandler(ConfigurationSavedEvent, value); }
        remove { RemoveHandler(ConfigurationSavedEvent, value); }
    }

    public event RoutedEventHandler ConfigurationClosed
    {
        add { AddHandler(ConfigurationClosedEvent, value); }
        remove { RemoveHandler(ConfigurationClosedEvent, value); }
    }
    #endregion
}

SystemConfigurationView:

public partial class SystemConfigurationView : UserControl
{
    static SystemConfigurationView()
    {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent("ConfigurationSaved",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SystemConfigurationView));

        ConfigurationClosedEvent = EventManager.RegisterRoutedEvent("ConfigurationClosed",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SystemConfigurationView));
    }

    #region ROUTED_EVENTS_RELATED
    public static readonly RoutedEvent ConfigurationSavedEvent;
    public static readonly RoutedEvent ConfigurationClosedEvent;

    public event RoutedEventHandler ConfigurationSaved
    {
        add { AddHandler(ConfigurationSavedEvent, value); }
        remove { RemoveHandler(ConfigurationSavedEvent, value); }
    }

    public event RoutedEventHandler ConfigurationClosed
    {
        add { AddHandler(ConfigurationClosedEvent, value); }
        remove { RemoveHandler(ConfigurationClosedEvent, value); }
    }
    #endregion
}

UserConfigurationView:

public partial class UserConfigurationView : UserControl
{
    static UserConfigurationView()
    {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent("ConfigurationSaved",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UserConfigurationView));

        ConfigurationClosedEvent = EventManager.RegisterRoutedEvent("ConfigurationClosed",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UserConfigurationView));
    }

    #region ROUTED_EVENTS_RELATED
    public static readonly RoutedEvent ConfigurationSavedEvent;
    public static readonly RoutedEvent ConfigurationClosedEvent;

    public event RoutedEventHandler ConfigurationSaved
    {
        add { AddHandler(ConfigurationSavedEvent, value); }
        remove { RemoveHandler(ConfigurationSavedEvent, value); }
    }

    public event RoutedEventHandler ConfigurationClosed
    {
        add { AddHandler(ConfigurationClosedEvent, value); }
        remove { RemoveHandler(ConfigurationClosedEvent, value); }
    }
    #endregion
}

When I’m using these classes I’m getting TypeInitializationException with the message:

RoutedEvent Name ‘ConfigurationSaved’ for OwnerType ‘baskcode.Admin.Controls.AccountConfigurationView’ already used.

Same exception is thrown if I try to load any of the other controls. I’m not able to rectify the problem. Please help me in this regard.

I’m using .Net version 4

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:29:19+00:00Added an answer on May 22, 2026 at 2:29 pm

    I assume that you are initializing your control more than once. You can’t register the same routed event name more than once.

    Try this (for one RoutedEvent):

    RoutedEvent[] x = EventManager.GetRoutedEventsForOwner(typeof(UserConfigurationView));
    
    if(x == null) {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent(
            "ConfigurationSaved",
            RoutingStrategy.Bubble,
            typeof(RoutedEventHandler),
            typeof(UserConfigurationView)
        );
    }
    

    And this (for multiple instanaces) : in your case

    using System.Linq;
    
    ...
    
    RoutedEvent[] x = EventManager.GetRoutedEvents();
    
    if(!x.Contains(ConfigurationSaved)) {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent(
            "ConfigurationSaved",
            RoutingStrategy.Bubble,
            typeof(RoutedEventHandler), 
            typeof(UserConfigurationView)
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WPF validation system performs intial validatation of an object (I mean - all fields
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
WPF Controls are divided into various baskets. Some controls belong to System.Windows.Controls namespace and
In WPF it was possible to organise the XAML for multiple user controls by
In WPF, C# application, I have 4 checkboxes, select all team personal subteam. As
WPF doesn't provide the ability to have a window that allows resize but doesn't
WPF applications are, at its core, managed applications? Right? So, I have to choose
WPF and Silverlight have a data binding model whereby I can provide a Binding
WPF 4.0 is a buzzword these days which is the latest version of WPF,
WPF appears to be splitting my controls diagonally. What am I doing wrong? The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.