注册一个自定义的URI协议处理来自XAML的自定义资源加载 [英] Registering a custom URI protocol to handle custom resource loading from XAML

查看:256
本文介绍了注册一个自定义的URI协议处理来自XAML的自定义资源加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的地方XAML的宽松位(和一些相关的IronPython code)将动态加载和执行客户端应用程序的项目。该客户端将使用自定义的WCF服务(和一些本地缓存)来检索XAML,支持脚本和相关资源(图标,图像等)。

I'm working on a project where loose bits of XAML (and some associated IronPython code) will be dynamically loaded and executed by a client application. The client will be using a custom WCF service (and some local caching) to retrieve the XAML, backing scripts, and related resources (icons, images, etc..).

我想注册一个自定义的URI协议/方案,使其更容易为动态包的开发人员可以参考他们的资源,如下所示:

I would like to register a custom URI protocol/scheme to make it easier for the developers of the dynamic packages to reference their resources, like the following:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <ResourceDictionary Source="custom://MyPackage/Icons.xaml"  />
                <ResourceDictionary Source="custom://MyPackage/Styles.xaml" />
                <!--                        ^^^^^^                         -->

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
</UserControl>

据我所知道的,我可以得出一个自定义的 UriParser 注册它,但似乎只是的一半。剩下的工作就是提供力所能及的组成部分是要解决自定义的URI和检索所需的内容。

As far as I can tell, I can derive a custom UriParser and register it, but that only seems to be half the battle. The remaining work is to provide whatever component is necessary to resolve the custom URI and retrieve the required content.

是否有可能提供或重写功能在WPF允许它叫我的自定义数据服务时,遇到了我的自定义的URI呢?或者,如果这是不可能的,也是没有任何一种替代的?

Is it possible to provide or override functionality in WPF to allow it to call my custom data service when one of my custom URIs is encountered? Or, if this is impossible, is there any sort of alternative?

推荐答案

据我了解,你需要创建一个类派生自的WebRequest 并用它注册< A HREF =htt​​p://msdn.microsoft.com/en-us/library/system.net.webrequest.register$p$pfix.aspx相对=nofollow> WebRequest.Register preFIX

From what I understand, you need to create a class that derives from WebRequest and register it with WebRequest.RegisterPrefix.

这篇关于注册一个自定义的URI协议处理来自XAML的自定义资源加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆