Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在代码隐藏中,我需要从 XAML 资源加载一个 Page 对象,并且我明确需要结果是 Page 类的对象的一个实例。我四处搜索并找到了一些涉及 XamlReader 等的解决方案,但它们看起来都有些奇怪和复杂,几乎就像 hacks。有什么简单而“正常”的方法吗?
Page p = (Page)Application.LoadComponent(new Uri(@"relative/uri/to/xaml/file.xaml", UriKind.Relative));
有关更多详细信息,请参阅 msdn 参考页面