【问题标题】:silverlight resource incompatibility with VS designer?silverlight 资源与 VS 设计器不兼容?
【发布时间】:2011-04-08 03:02:59
【问题描述】:

我在 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 在它的构造函数中调用了一个 web 服务,但我很确定这是 VS 设计器的问题,而不是类的问题。我可以编译并运行该项目,它的运行方式与我希望它从 cassini 完全一样,填充组合框。只是 VS 设计师不合作。

谁能告诉我如何让设计者认识到 ServiceReferences.ClientConfig 可用这一事实?

【问题讨论】:

  • 作为后续,我通过从我的代码中删除对 Web 服务的任何引用来确认此问题与 ServiceReferences.ClientConfig 有关。只有在 AlignmentsViewModel 的定义中某处发现 web 服务调用时,设计者才会抱怨。

标签: silverlight mvvm resources silverlight-4.0


【解决方案1】:

Visual Studio 设计器在显示控件时实际上调用了它的构造函数。如果您从构造函数或 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"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多