我正在构建一个自托管的WCF服务.我正在构建一个特殊的数据结构,以实现非常灵活的数据传输.到目前为止,我测试我的结构是否可以使用DataContractSerializer进行序列化.这工作正常,我很高兴,但有些东西让我烦恼:
在我的XML输出中有许多重新定义的xmlns属性,例如:
xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:b="http://www.w3.org/2001/XMLSchema"
Run Code Online (Sandbox Code Playgroud)
这应该在根元素中更好地定义一次,以便可以简单地优化字节.有没有办法将自定义命名空间信息添加到根元素?
这是一个更大的例子来证明我的意思:
<DataObject xmlns="http://schemas.datacontract.org/2004/07/Test"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>ID</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">1</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>Value</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">42</a:Value>
</a:KeyValueOfstringanyType>
</Data>
<Data xmlns:a="...">...</Data>
<Data xmlns:a="...">...</Data>
<Data xmlns:a="...">...</Data>
</DataObject>
Run Code Online (Sandbox Code Playgroud)
我想要的是这样的:
<DataObject xmlns="http://schemas.datacontract.org/2004/07/Test"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:b="http://www.w3.org/2001/XMLSchema">
<Data>
<a:KeyValueOfstringanyType>
<a:Key>ID</a:Key>
<a:Value i:type="b:int">1</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>Value</a:Key>
<a:Value i:type="b:int">42</a:Value>
</a:KeyValueOfstringanyType>
</Data>
<Data>...</Data>
<Data>...</Data>
<Data>...</Data>
</DataObject>
Run Code Online (Sandbox Code Playgroud) 以下XML模式无法使用以下XML实例文档进行验证.有没有办法重写模式,以便实例文档在给定的约束内验证?
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="sample-attribute" type="xs:string" />
<xs:element name="sample-element">
<xs:complexType>
<xs:attribute ref="sample-attribute" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<sample-element xmlns="http://tempuri.org/XMLSchema.xsd" sample-attribute="test" />
Run Code Online (Sandbox Code Playgroud) 标准颜色方案中的两个示例文本框和以下构造函数产生具有灰色前景的Box1和具有黑色前景的Box2,因为已经明确设置了Box2的前景颜色.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Box2.Foreground = Brushes.Black;
Box1.IsEnabled = false;
Box2.IsEnabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我想"取消设置"前景色,以便Box2"回退"为默认的禁用颜色,并且当IsEnabled设置为false时具有灰色前景.这可能吗?如果是这样,它是如何完成的?
将Foreground属性设置为null不具有所需的效果.我想尽可能避免将Foreground颜色显式设置为Gray,因为它与自定义颜色方案不兼容.
是否有一种干净的方法来访问作为启动 WPF 应用程序的 AppDomain.ExecuteAssembly 调用的一部分传递的命令行参数?
我正在一个单独的应用程序域中启动一个 WPF 应用程序,并将参数传递给该应用程序,如下所示:
AppDomain moduleDomain = AppDomain.CreateDomain("Friendly Name");
moduleDomain.ExecuteAssembly(path, new[] { "arg1", "arg2" });
Run Code Online (Sandbox Code Playgroud)
有一种解决方法可以访问这些参数,因为Environment.GetCommandLineArgs()和StartupEventArgs都返回原始应用程序的命令行参数,而不是使用ExecuteAssembly() 启动的命令行参数。
我想访问传递给 WPF 应用程序的参数,而无需手动定义 Main 方法,最好使用 StartupEventArgs。有办法这样做吗?
在单独的进程中启动 WPF 应用程序是可行的,但会降低性能并使调试变得复杂。