c# - 使用路径/URI 打开一个 wpf 页面

标签 c# wpf

我想做这样的事情:

var iFrame = new Frame();
var iPage = new Page(new Uri("/Views/MyPage.xaml", UriKind.Relative));
//                              ^ this must be the parameter on creating the page

iFrame.Content = iView;
tabCtrl.Content = iFrame;

其中,我想使用路径打开页面,而不是像这样实例化功能正确的页面本身:

var iFrame = new Frame();
var iPage = new MyPage();

iFrame.Content = iView;
tabCtrl.Content = iFrame;

我的想法是为存储在数据库中的页面使用维护路径。 有什么想法吗?

最佳答案

是这样的吗?

    System.Uri resource =  new System.Uri(@"Views\MyPage.xaml", System.UriKind.RelativeOrAbsolute);
    Something.Content = System.Windows.Application.LoadComponent(resource);

关于c# - 使用路径/URI 打开一个 wpf 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34171470/

相关文章:

c# - 从数组 C# 中删除字符串

c# - 在 C# 中测量执行时间

c# - 通过 RESTful webservice 返回图片

WPF:如何调用 Dispatcher.BeginInvoke *only* 当队列中没有要调用的内容时?

c# - 绑定(bind)到显式接口(interface)实现的 SortDescription

c# - 用于验证字符串仅包含 0 - 9、+、#、*、[ 和 ] 的正则表达式

c# - 获取在RichTextBox中输入的最后一个词c#

wpf - 通过隐藏代码更新 WPF DataGrid 列标题文本

wpf - 创建 ViewModel : do it before or after model data is available?

WPF CollectionViewSource 分组