2015-02-24 25 views
1

我有两个xaml文件。 main.xaml文件和一个名为test.xaml的辅助文件如何从多个XAML文件的WPF代码中访问元素

在main.xaml文件中,我使用(带有框架)test.xaml文件。

<Frame x:Name="test" Source="test.xaml"/> 

所有元素都有使用x:names标签的名称。 如何以编程方式从main.xaml代码后面的文件中访问test.xaml中的元素?

Zjeriet

回答

1

如何编程访问元素

从你的主页的代码背后投射的source元素的类实例的名称,其test.xaml基于断和访问在代码隐藏中适当。

var myPage = test.Source as {InsertClassNameHere}; 
+0

我已经添加 '×:类= “Skeiron.TestPage”' 到test.xaml页 并补充 'VAR MYPAGE = NMSRing.Source为{Skeiron.TestPage};' 我的主页的代码。 我收到预期类型的​​错误。 – Zjerre 2015-02-25 08:42:31

+0

@Zjerre你的意思是它找不到'Skeiron.TestPage'类? – OmegaMan 2015-02-25 13:41:04

+0

是的,它看起来像。 我没有test.xaml页面的文件背后的代码。那是问题吗。 test.xaml与 – Zjerre 2015-02-25 16:52:21

相关问题