WPF で、「ユーザー構成」、「システム構成」、「アカウント構成」の 3 つの UserControls を作成しました。これらすべてのユーザー コントロールには、[保存] ボタンと [キャンセル] ボタンがあります。これらのボタンをクリックすると、それぞれのクラスで宣言および定義されたルーティング イベントが発生します。保存ボタンをクリックすると「ConfigurationSaved」イベントが発生し、キャンセル ボタンをクリックすると「ConfigurationCancelled」イベントが発生します。
これらのイベントが発生すると、ユーザー コントロールをホストするコンテナーが構成を保存します。
すべてのクラスのルーティング イベント定義のコード スニペットは次のとおりです。
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
}
システム構成ビュー:
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
}
ユーザー構成ビュー:
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
}
これらのクラスを使用していると、次のメッセージで TypeInitializationException が発生します。
OwnerType 'baskcode.Admin.Controls.AccountConfigurationView' の RoutedEvent 名 'ConfigurationSaved' は既に使用されています。
他のコントロールを読み込もうとすると、同じ例外がスローされます。問題を修正することはできません。この点で私を助けてください。
私は.Netバージョン4を使用しています
ありがとう。