首页 \ 问答 \ 在WPF中的同一解决方案中,在运行时在不同的类库项目中更改资源文件(Change Resource file at runtime in different class library project in same solution in WPF)

在WPF中的同一解决方案中,在运行时在不同的类库项目中更改资源文件(Change Resource file at runtime in different class library project in same solution in WPF)

我有这些项目的解决方案:

1. Clinica (Type是Windows应用程序),( MainWindow.xaml在这里)

2. Ferhad.Wpf.Core (类型是类库),(有三个文件: Resources.xamlOrangeResource.xamlBlueResource.xaml

Resources.xaml看起来像这样:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.Core;component/BlueResource.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

现在,从MainWindow.xaml.cs我想清除并将OrangeReource.xaml添加到Resources.xaml

我怎么能这样做:到目前为止我试过这个:

string fileName = "pack://application:,,,/Ferhad.Wpf.Core;component/OrangeReSource.xaml";
if (System.IO.File.Exists(fileName))
{
    using (FileStream fs = new FileStream(fileName, FileMode.Open))
    {
        ResourceDictionary dic = (ResourceDictionary)XamlReader.Load(fs);

        string fileNameR = "pack://application:,,,/Ferhad.Wpf.Core;component/Resources.xaml";
        if (System.IO.File.Exists(fileNameR))
        {
            using (FileStream fsR = new FileStream(fileNameR, FileMode.Open))
            {
                ResourceDictionary dicR = (ResourceDictionary)XamlReader.Load(fsR);
                dicR.MergedDictionaries.Clear();
                dicR.MergedDictionaries.Add(dic);
            }
        }
    }
}

谢谢。


I have a solution with these projects:

1.Clinica (Type is Windows Application),(MainWindow.xaml is here)

2.Ferhad.Wpf.Core (Type is Class Library), (There are three files: Resources.xaml, OrangeResource.xaml, BlueResource.xaml)

The Resources.xaml looks like that:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.Core;component/BlueResource.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Now, from MainWindow.xaml.cs I want to clear and add OrangeReource.xaml to Resources.xaml.

How can i do that: So far I have tried this:

string fileName = "pack://application:,,,/Ferhad.Wpf.Core;component/OrangeReSource.xaml";
if (System.IO.File.Exists(fileName))
{
    using (FileStream fs = new FileStream(fileName, FileMode.Open))
    {
        ResourceDictionary dic = (ResourceDictionary)XamlReader.Load(fs);

        string fileNameR = "pack://application:,,,/Ferhad.Wpf.Core;component/Resources.xaml";
        if (System.IO.File.Exists(fileNameR))
        {
            using (FileStream fsR = new FileStream(fileNameR, FileMode.Open))
            {
                ResourceDictionary dicR = (ResourceDictionary)XamlReader.Load(fsR);
                dicR.MergedDictionaries.Clear();
                dicR.MergedDictionaries.Add(dic);
            }
        }
    }
}

Thanks.


原文:https://stackoverflow.com/questions/13429622
更新时间:2023-04-26 07:04

最满意答案

看起来Java / AXIS Web服务使用SOAP(第5节)编码。 这是倒退,看到这些日子很奇怪。

你从哪里获得网络服务? 它运行多久了? 你有能力改变它吗? AXIS或AXIS2? 什么版本? 对于AXIS1,从AXIS v1.1开始的任何内容都应该可以正常工作,但我建议更新到v1.4。 如果可能的话转移到AXIS2,并使用v1.4。 (令人困惑的是,AXIS和AXIS2的版本号相同。)

为什么Java方面想要使用SOAP编码? Java方面是采用WSDL的第一种方法,还是这些动态生成的WSDL事物之一? 如果您先从WSDL + XSD开始 ,并将自己局限于doc / lit webservices,并将xmlschema的使用限制在一些不那么奇特的部分:原始类型,结构和数组中, AXIS和.NET一起工作得很好 。 您可以嵌套到任何层次:包含数组的结构数组,包含结构数组的结构等。

附录 :如果从Java对象模型开始,并尝试从它动态生成一个有线接口(例如,WSDL),那么您的互操作性往往会变得更糟,并且您倾向于考虑通过线路发送对象的消息,这可能是有害的。

要避免的事情:列表,限制,替换组和其他古怪的事情。


It seems the Java/AXIS web service is using SOAP (section 5) encoding. This is a throwback, and is very odd to see these days.

Where'd you get the web service? how long has it been running? Do you have the ability to change it? AXIS or AXIS2? What version? For AXIS1, anything from AXIS v1.1 onward should work ok, but I'd advise updating to v1.4. If possible move to AXIS2, and use v1.4. (Confusingly, AXIS and AXIS2 are at the same version number.)

Why does the Java side want to use SOAP encoding? Did the Java side take a WSDL first approach, or is this one of those dynamically-generated WSDL things? AXIS and .NET work together just fine, if you start with WSDL+XSD first, and confine yourself to doc/lit webservices and confine your use of xmlschema to the less exotic pieces: primitives, and structures and arrays of same. You can nest to any level: arrays of structures containing arrays, structures containing arrays of structures, etc etc.

Addendum: If you start with your Java object model, and try to dynamically generate a wire-interface from it (eg, WSDL), you tend to get much worse interop, and you tend to think in terms of sending objects over the wire instead of messages, which can be harmful.

Things to avoid: lists, restrictions, substitution groups, and other wacky things.

相关问答

更多
  • 好的,我最终找到了答案。 看起来像显式设置SOAP操作解决了问题。 它可以这样做: options.setAction("urn:getFileServers"); OK, I found the answer eventually. Looks like explicitly setting the SOAP action solves the problem. It can be done like this: options.setAction("urn:getFileServers");
  • 看起来Java / AXIS Web服务使用SOAP(第5节)编码。 这是倒退,看到这些日子很奇怪。 你从哪里获得网络服务? 它运行多久了? 你有能力改变它吗? AXIS或AXIS2? 什么版本? 对于AXIS1,从AXIS v1.1开始的任何内容都应该可以正常工作,但我建议更新到v1.4。 如果可能的话转移到AXIS2,并使用v1.4。 (令人困惑的是,AXIS和AXIS2的版本号相同。) 为什么Java方面想要使用SOAP编码? Java方面是采用WSDL的第一种方法,还是这些动态生成的WSDL事物之一 ...
  • 它清楚地说在运行时你的servlet找不到存根...你是否将存根类保存在servlet可以访问它的类路径中? 确保存根在类路径中可用。 It clearly says at runtime your servlet couldn't find the stubs..have you kept the stub classes in the classpath where the servlet can access it? Make sure the stubs are available in the c ...
  • 这是通用的WCF“发生了一些不好的事”错误消息。 这不会有太大帮助。 处理办法: 确保您调用的Web服务自行运行 - 否则解决它! 通过在WCF服务中包含错误详细信息(如在错误消息中所述)启用详细错误信息( 仅在DEV环境中执行此操作!从不在生产中...) 尝试在Visual Studio中启动WCF服务并调试正在发生的事情 为了启用详细的错误报告,您需要将此部分添加到WCF服务的配置中:
    您正在尝试实例化抽象类或接口。 这就是抛出InstantiationError的原因。 根据文档,它陈述如下 公共类InstantiationError扩展了IncompatibleClassChangeError 当应用程序尝试使用Java新构造来实例化抽象类或接口时抛出。通常,编译器会捕获此错误; 如果类的定义不兼容地更改,则此错误只能在运行时发生。 you are trying to instantiate an abstract class or interface. that's why Inst ...
  • 该服务的WSDL应位于以下URL: /webservice/WebServiceFOX.asmx?wsdl ,其中主机位于托管服务的任何位置(图像中的localhost或问题中的192.168.1.15 )。 发送SOAP请求的端点应为/webservice/WebServiceFOX.asmx 。 ASP.NET生成您看到的那些页面,允许您使用GET请求测试浏览器内的服务。 在这些页面中应该有一个指向WSDL的链接(在英语中它是一个名为“服务描述”的链接)。 The ...
  • Axis2检查服务元数据文件“avax.xml.stream.XMLStreamException:Service Repository中不存在文件!File = META-INF / ServiceData.xml”..您的服务.aar文件夹结构是否正确? 在* .AAr文件中,您应该有META_INF文件和您的实现。 test.aar|-----META_INF | |......folder contains classes Axis2 checks the se ...
  • 我相信,首先您需要一种异步服务通信的设计模式,以更好地满足您的系统要求。 1 - 异步响应处理程序 应用程序创建一个分离的线程来处理服务器响应,使主线程可以自由执行其他任务 当响应到达时,通知主线程接收响应。 有两种实现策略:池化和回调。 使用池时,主线程会检查第二个线程中的响应,直到响应可用。 使用回调,第二个线程使用回调方法通知主线程。 2 - 请求/确认 这种模式基于服务器参与来实现异步通信。 该进程不是将进程拆分为两个客户端线程,而是分为客户端和服务器之间的两个不同的事务。 这种模式需要某种相关性识 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。