ユーザーコントロールをページとして渡そうとしています。私はボタンで作業しています。クリックイベントを含むメニューを追加すると、それはもはや機能しません。メニュー項目とボタンイベントに関する問題
これは、メインレイアウトにどのUserControlを入力するかを示すコードブロックです。この部分はボタンを使用するだけで動作します。
private void btnGeneral_Click(object sender, RoutedEventArgs e)
{
PanelMainContent.Children.Clear();
Button button = (Button)e.OriginalSource;
PanelMainWrapper.Header = button.Content;
Type type = this.GetType();
Assembly assembly = type.Assembly;
PanelMainContent.Children.Add(_userControls[button.Tag.ToString()]);
}
この部分はのMenuItemとボタンを使用しようと、それは
public void btnGeneral_Click(object sender, RoutedEventArgs e)
{
PanelMainContent.Children.Clear();
MenuItem menuItem = (MenuItem)e.OriginalSource;
Button button = (Button)e.OriginalSource;
if (e.OriginalSource == menuItem)
{
PanelMainWrapper.Header = menuItem.Header;
Type type = this.GetType();
Assembly assembly = type.Assembly;
PanelMainContent.Children.Add(_userControls[menuItem.Tag.ToString()]);
}
if (e.OriginalSource == button)
{
PanelMainWrapper.Header = button.Content;
Type type = this.GetType();
Assembly assembly = type.Assembly;
PanelMainContent.Children.Add(_userControls[button.Tag.ToString()]);
}
}
エラー(S)Iレシーブを動作しません。
XamlParseException:
The invocation of the constructor on type 'Test.MainWindow' that matches the specified binding constraints threw an exception.' Line number '5' and line position '9'
InnerException
{"Unable to cast object of type 'System.Windows.Controls.Button' to type 'System.Windows.Controls.MenuItem'."}
いずれかのガイダンスをいただければ幸いです。
ありがとうございます!