WPF 设计器错误值不能为空。参数名称:模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24292365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF designer error Value cannot be null. Parameter name: pattern
提问by user2943131
I've seen a lot of other ObjectDataProvider questions where the Parameter name: type, name, whatever, cannot be null. Those questions are all due to actualparameters not being set. As far as I can tell, there is no "pattern" parameter for an ObjectDataProvider. The following markup produces "Value cannot be null. Parameter name: pattern", with the accompanying blue squiggle underline. Occasionally the designer throws an exception and fails to load, however pressing the reload button loads the page. The code and markup compile and run as expected. What is causing this?
我已经看到很多其他 ObjectDataProvider 问题,其中参数名称:类型、名称等不能为空。这些问题都是由于没有设置实际参数。据我所知,ObjectDataProvider 没有“模式”参数。以下标记生成“值不能为空。参数名称:模式”,并带有蓝色波浪线下划线。有时设计器会抛出异常并且无法加载,但是按下重新加载按钮会加载页面。代码和标记按预期编译和运行。这是什么原因造成的?
<Page.Resources>
...
<ObjectDataProvider ObjectType="{x:Type local:AutoFillBox}" MethodName="RecUpdateOutput" x:Key="odpOutput">
<ObjectDataProvider.MethodParameters>
<sys:String>08:00</sys:String>
<sys:String>12:00</sys:String>
<sys:String>13:00</sys:String>
<sys:String>18:00</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Page.Resources>
Part of the class, wanted to note this is not a custom control, just a poor naming choice:
类的一部分,要注意这不是自定义控件,只是一个糟糕的命名选择:
public partial class AutoFillBox
{
public AutoFillBox()
{ //default }
public string RecUpdateOutput(string time1, string time2, string time3, string time4)
{
//do stuff
}
}
It's the only ObjectDataProvider on the page, and if I remove the 4th string parameter the error goes away. Additionally, the method it calls does take 4 strings, and returns a string so I can bind it's result to an output textbox. I use a similar ObjectDataProvider on a different page with a similar method and signature, and it also shows the same error. What the heck is going on here?
它是页面上唯一的 ObjectDataProvider,如果我删除第 4 个字符串参数,错误就会消失。此外,它调用的方法确实需要 4 个字符串,并返回一个字符串,因此我可以将其结果绑定到输出文本框。我在具有类似方法和签名的不同页面上使用了类似的 ObjectDataProvider,它也显示了相同的错误。这到底是怎么回事?
Visual Studio Ultimate 2013, Windows 7 Professional, targeting .net 4.5
Visual Studio Ultimate 2013,Windows 7 Professional,面向 .net 4.5
采纳答案by user3786916
I don't believe it's a VS bug. Try adding the property IsAsynchronous="True" to the ObjectDataProvider and that should eliminate the designer error. The property defaults to False and the designer will try to create the object in the active context. Here's link:
我不相信这是一个 VS 错误。尝试将 IsAsynchronous="True" 属性添加到 ObjectDataProvider,这应该可以消除设计器错误。该属性默认为 False,设计器将尝试在活动上下文中创建对象。这是链接:
Worked for me. Hope it works for you.
对我来说有效。希望对你有效。

