开发者

silverlight resource incompatibility with VS designer?

I have the following defined at the top of my 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>

Then later on I use the AlignmentListViewSource as an ItemSource that I bind to a ComboBox. Everything seems to work correctly except the Designer doesn't like the AlignmentsVM resource. It complains like this:

[Xml_CannotFindFileInXapPackage]
Arguments: ServiceReferences.ClientConfig
Debugging resource strings are unavailabl开发者_开发问答e. 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()

I verified that the ServiceReferences.ClientConfig file IS part of the SilverlightUI project and is marked as "Content".

The AlignmentsViewModel calls a webservice in it's constructor, but I'm pretty sure this is a problem with the VS designer, not the class. I can compile and run the project and it runs exactly like I want it to from cassini, populating the combo box. it's just the VS designer that isn't cooperating.

Can anyone advise me as to how I can get the designer to recognize the fact that ServiceReferences.ClientConfig IS available?


The Visual Studio Designer actually calls the Control's constructor when showing it. If you access resources from the constructor or the UserControl_Loaded event handler, an exception occurs. I've worked around this (reasonable) limitations by providing save values while in designer.

Field declaration

static bool isInDesignMode;

Constructor logic

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

Method logic

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜