I have been working fine with MVVM Light on a silverlight 4 Windows Phone 7 project in Visual Studio 2010 and Blend 4 for sometime.
Then suddenly I start getting the "Cannot create an instance of "ViewModelLocator"" error in both VS 2010 and Blend. Can't work out why it should appear now. Any ideas on how I can possibly track down if something somewhere has changed that I have not spotted.
The only change I made, and then put back, was to add a "d:" infront of the data context expression in one of the user controls. I had the idea of binding in design, but programmatically binding in a delayed manner at run time.
I see others have posted this problem, but the answers refer to a bug in Blend, which has apparently been fixed. Also this is occuring in VS2010 too.
App.xaml looks like
<Application x:Class="BillSplitter2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:vm="clr-namespace:BillSplitter2.ViewModel"
xmlns:converters="clr-namespace:HardMediumSoft.WP7.Tools.Converters;assembly=HardMediumSoft.WP7.Tools">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>
<!--Localization String Library-->
<local:LocalizedStrings xmlns:local="clr-namespace:BillSplitter2.Utilities"
x:Key="LocalizedStrings" />
<!--Converters -->
<converters:FloatConverter x:Key="FloatConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:StringToBrush x:Key="StringToBrushConverter" />
</ResourceDictionary>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService Launching="Application_Launching"
Closing="Application_Closing"
Activated="Application_Activated"
Deactivated="Application_Deactivated" />
</Application.ApplicationLifetimeObjects>
Thanks to the recommendation above, I started to investigate the constructor of my ViewModel. Although I had no errors, I did find that belnd had issues with event listeners and handlers.
I was using the
if (IsInDesignMode)
{
//populate values here for blend
}
else
{
//runtime initiation
}
to populate some values for design time. I would initiate values in the model by setting their properties. This was all fine until I started adding more complex event handling routines based on property changes.
To rectify this and recover my 'blendability' I did two things!
Set private fields rather than properties in the IsDesignMode section. This avoid PropertyChanged events firing.
Added IsInDesignMode detection in event handlers that remained a problem and skipped any cascded updating.
Hope this helps!
This has previously been answered here. Verify that the issue is not an error during object instance creation (constructor, etc.)
Related
The XAML designer is not updating any of the transform values like rotation, translation, etc. It works fine otherwise, it also worker before, it just stopped working suddenly and I don't know what I did.
<Ellipse />
<Rectangle WidthRequest="5" AnchorX="0.5" AnchorY="0.8" TranslationY="-40" Fill="Black" />
<Rectangle AnchorX="0.5" AnchorY="0.8" TranslationY="-40" />
In the above code I used the Translation its not reflecting only in the designer, but if I run the app its updated.
That's what its look like in the designer.
That's what its looks in the output when I run the application, its not reflecting in the XAML designer. So I have to run application every time I need see the result of any update when I use any kind of transform effect.
Try to restart your VS. If the XAML designer does not work everytime with this project or the new project, you could try to repair the VS.
I am working on a legacy product. I need to make regions of a complex UI optional, based on build constants. It is not feasible to move these regions into controls, so I am using AlternateContent Tags (mc:AlternateContent).
This works perfectly, at compilation and the application runs as expected.
However, the IDE claims one error for each AlternateContent, and enclosed Choice Tag, and will not load the Design window/preview (in VS or Blend):
The name "AlternateContent" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"
The name "Choice" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"
I have tried, rebuilding, cleaning and rebuilding, changing build settings between release, debug, x86, x64, and rebooting. Nothing helps. It even give the same errors in Blend.
I am hoping that this is just something stupid that I am doing, and I can fix it; or possibly a newer Namespace URI I should be using. If I cannot resolve the errors, I am hoping someone knows a trick to suppress these errors in the IDE, so can use it.
I have a fully updated VS2013 Premium installation. However, It has the glitch on a test machine running VS14 CTP, and another running VS2012 (fully updated), both without any add-ins; so I have to assume it is not a problem with my PCs install.
A little late to the party, but if you add the mc tag to your Ignorable attribute the error goes away. Your content won't show in the designer but worked for me when I compiled the different flavours of my project.
<UserControl...
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conditional="defined-in-assembly.cs"
mc:Ignorable="d mc"/>
What about this:
public class BuildConstants
{
public bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
and the xaml:
<Application.Resources>
<BooleanToVisibilityConverter x:Name="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
<l:BuildConstants x:Key="BuildConstants" />
</Application.Resources>
<Grid Visibility="{Binding IsDebug, Source={StaticResource BuildConstants}, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Text="This will be visible only when DEBUG build constant is present"></TextBlock>
</Grid>
I am designing an app for Windows Phone using the Viual Studio XAML designer. My page is to long to fit into a page so I had to put it inside a ScrollViewer and Grid. This works but my problem is that the designer does not allow me to see (and therefore to some extent interact) with these elements outside the page. Is there any setting or something that I can use to be able to interact with these elements?
Add the following to the XAML element of the page:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignHeight="<desired height>"
i.e.:
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignHeight="1600"
....more attributes...
>
<!-- other stuff -->
</phone:PhoneApplicationPage>
The xml namespace definition for "d" is probably already present, and the same can be done for the design time width, of course.
I am using the Consumer Preview of Windows 8 to create a Metro app. Whenever I add a new IValueConverter to a XAML page I receive the following exceptions from within the StandardStyles.xaml file:
The name "DictionaryEntry" does not exist in the namespace "using:System.Collections"
The errors point to this section of the StandardStyles.xaml file:
<ResourceDictionary.ThemeDictionaries>
<Collections:DictionaryEntry x:Key="Default">
<Collections:DictionaryEntry.Value>
<ResourceDictionary>
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</Collections:DictionaryEntry.Value>
</Collections:DictionaryEntry>
<Collections:DictionaryEntry x:Key="HighContrast">
<Collections:DictionaryEntry.Value>
<ResourceDictionary>
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</Collections:DictionaryEntry.Value>
</Collections:DictionaryEntry>
</ResourceDictionary.ThemeDictionaries>
This file was added automatically when I created a new Metro App project from the default Metro App project templates. The file compiled and ran fine before I added a IValueConverter to a page. The issue happens every time I add a IValueConverter, regardless of which project template I use, and regardless of if I add the IValueConverter using Expression Blend or Visual Studio.
This could just be a bug in the Consumer Preview release, but it seems like such a fundamental piece of work, that I figured it was worth asking here if anyone else has run into this issue and, if so, how were you able to solve or workaround it?
We are currently migrating our app from VB6 to Net. As the Net forms will be in the minority we want them to blend in as good as possible with the VB6 forms. I thought that forcibly applying the Classic theme would accomplish this. This should be easy but I can't find how to do it. The examples provided target the Aero theme or Net3 which seems to have differently named referenced assemblies.
There are two ways to accomplish this:
Reference the classic.xaml file that is embedded in the Framework:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/classic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
`
Download the extracted classic.xaml file from here
This file holds a reference to the PresentationUI.dll which does not seem to be part of Net 4 framework. There is just one quixotic Control using this reference, so when you remove the reference and the control you are set to go!
More info here