簡単なプログラムがあります。ボタンとフレームのある基本的なキャンバスがあります。
<Canvas Width="1200" Height="600" Name="frontPanel" Background="Blue">
<Button Width="200" Height="90" Content="flipme" Click="flipme" VerticalAlignment="Top" HorizontalAlignment="Left" >
<Button.RenderTransform>
<TransformGroup>
<TranslateTransform x:Name="BtnMove" X="500" Y="255" />
</TransformGroup>
</Button.RenderTransform>
</Button>
<Frame Name="wow" Width="1200" Height="600"></Frame>
</Canvas>
私が達成したいのはこれです。バックエンドコーディングを使用して、別のxamlページを現在のページにロードします。私がオンラインで見たのは、別のページをロードし、ロード後にイベントハンドラーを追加する方法だけです。
ページをロードする私のコードは次のとおりです。
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string commonPath = basePath.Remove(basePath.Length - @"\bin\Debug\".Length);
wow.Source = (new Uri(commonPath + "\\Page2.xaml"));
page2.xamlにクリックメソッドがアタッチされていない場合は機能しますが、page2.xamlのボタンにクリックイベントハンドラーをアタッチすると、プログラムは次のように通知します。
Failed to create a 'Click' from the text 'button1_Click_1'.' Line number '12' and line position '144'.
だから私の質問は、後でそれを割り当てることなく、ページとバックエンドコーディングを一緒にロードする方法はありますか?なぜなら、page2.xamlを、別のバックエンドコーディングを使用した別のページとして作成したからです。ページ1.xamlのpage2.xamlを、バックエンドコーディング(クリックイベントハンドラー)とともにロードする必要があります。私はウェブを検索しましたが、まだこの問題の解決策を見つけられないことを繰り返します。