【发布时间】:2012-05-30 08:21:21
【问题描述】:
我有一个简单的程序。它有一个带有按钮和框架的基本画布。
<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 制作为带有单独后端编码的单独页面。我需要在 page1.xaml 中加载 page2.xaml 及其后端编码(单击事件处理程序)。我重申,我已经搜索了网络,但仍然没有找到任何解决此问题的方法。
【问题讨论】: