silverlight资源与VS设计师不兼容?

时间:2010-09-04 02:35:16

标签: silverlight mvvm resources silverlight-4.0

我在XAML的顶部定义了以下内容:

<controls:ChildWindow 
    x:Class="MyProject.SilverlightUI.Views.CharacterGenerator"
    xmlns:my="clr-namespace:MyProject.SilverlightUI.ViewModels" 
>
<controls:ChildWindow.Resources>
    <my:AlignmentsViewModel x:Key="AlignmentsVM" ></my:AlignmentsViewModel>
    <CollectionViewSource x:Key="AlignmentListViewSource" Source="{Binding Path=Alignments, Source={StaticResource AlignmentsVM}}"></CollectionViewSource>
</controls:ChildWindow.Resources>

然后我使用AlignmentListViewSource作为我绑定到ComboBox的ItemSource。除了Designer不喜欢AlignmentsVM资源外,一切似乎都能正常工作。它抱怨这样:

[Xml_CannotFindFileInXapPackage]
Arguments: ServiceReferences.ClientConfig
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See [broken hyperlink]
   at System.Xml.XmlXapResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
   at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
   at System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup()

我验证了ServiceReferences.ClientConfig文件是SilverlightUI项目的一部分,并标记为“内容”。

AlignmentsViewModel在它的构造函数中调用webservice,但我很确定这是VS设计器的问题,而不是类。我可以编译并运行该项目,它的运行方式与我想要的cassini一样,填充组合框。只是VS设计师没有合作。

有人可以告诉我如何让设计师认识到ServiceReferences.ClientConfig可用吗?

1 个答案:

答案 0 :(得分:3)

Visual Studio Designer在显示时实际调用了Control的构造函数。如果从构造函数或UserControl_Loaded事件处理程序访问资源,则会发生异常。我通过在设计师中提供保存值来解决这个(合理的)限制。

现场声明

static bool isInDesignMode;

构造函数逻辑

// Check for design mode (the Visual Studio Designer is unable to find the AppSettings.xml)
bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this);

方法逻辑

string cultures = isInDesignMode ? "en,de" : ConfigurationManager.AppSettings["supportedCultures"];