d:DesignData issue, Visual Studio 2010 cant build after adding sample design data with Expression Blend 4 - visual-studio

VS 2010 solution and Silverlight project builds fine, then:
I open MyView.xaml view in Expression Blend 4
Add sample data from class (I use my class defined in the same project)
after I add new sample design data with Expression blend 4, everything looks fine, you see the added sample data in the EB 4 fine, you also see the data in VS 2010 designer too.
Close the EB 4, and next VS 2010 build is giving me this errors:
Error 7 XAML Namespace http://schemas.microsoft.com/expression/blend/2008 is not resolved. C:\Code\source\...myview.xaml
and:
Error 12 Object reference not set to an instance of an object. ... TestSampleData.xaml
when I open the TestSampleData.xaml I see that namespace for my class used to define sample data is not recognized.
However this namespace and the class itself exist in the same project!
If I remove the design data from the MyView.xaml:
d:DataContext="{d:DesignData /SampleData/TestSampleData.xaml}"
it builds fine and the namespace in TestSampleData.xaml is recognized this time??
and then if add:
d:DataContext="{d:DesignData /SampleData/TestSampleData.xaml}"
I again see in the VS 2010 designer sample data, but the next build fails and again I see studio cant find the namespace in my TestSampleData.xaml containing sample data.
That cycle is driving me crazy. Am I missing something here, is it not possible to have your class defining sample design data in the same project you have the MyView.xaml view??
cheers
Valko

I know this is and old question, but do you have the line mc:Ignorable="d" in your xaml? Without this line you will get this error.

Add this namespace
xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.TestSampleData"
Add this resource to a resource dictionary
<SampleData:TestSampleData x:Key="TestSampleData" d:IsDataSource="True"/>
Reference like this in your xaml
d:DataContext="{Binding Source={StaticResource TestSampleData}}"
I realise this is an old(ish) question but I hope this helps someone.

Related

Is there any way to find the C# code that is created from XAML with Xamarin?

Given some Xaml like this:
<headingView:HeadingView
x:Class="Test.Views.Decks.DeckBase.DeckMgmt.DeckMgmtPage2"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:headingView="clr-namespace:Test.Templates.Pages.HeadingView;assembly=Test"
xmlns:t="clr-namespace:Test.Templates"
BackIconVisible="True"
PageTitle="Mgmt">
<t:Stack>
<t:ContentFrame Heading="Reset">
<t:LinkGrid TapCommand="{Binding ResetDeckCmd}" Text1="Reset" />
</t:ContentFrame>
<t:ContentFrame Heading="Sort">
<t:LinkGrid Text1="Sort" />
</t:ContentFrame>
</t:Stack>
</headingView:HeadingView>
I don't need help in changing this to C# but I would like to know if there is any place or way I can find out the intermediate C# that is created?
Viewing the actual code generated by the compiler is tricky (I tried for a couple of hours but I could not find a way to directly view the code) - but it is possible to view the source code itself.
First of all - download .NET reflector and the appropriate Visual Studio extension.
https://visualstudio.microsoft.com/vs/preview/
Now we need to find the method that we want to decompile.
The method Xamarin.Forms.Xaml.Extensions.LoadFromXaml() is found in your page's xaml.g.cs file. According to Microsoft:
When Visual Studio builds a project containing a XAML file, it [the method] parses the XAML file to generate a C# code file (for example, MainPage.xaml.g.cs) that contains the definition of the InitializeComponent method:
The method in this case is the LoadFromXaml() method.
Now add a breakpoint like so:
Press F12 until you reach the following:
You will reach the 'Load' method:
You will see something like this:
From here - you can browse the rest of the XamlLoader class's source code:
Very interesting, isn't it? This is the closest thing to a solution that I got to.
I've just shared it as an image as I don't think it would be appropriate to share the full code as a code snippet.
It's not exactly what you're looking for - but I still hope this helped answer your question either way.

visual studio 2010 inserts using directives inside namespace

I have exactly opposite problem to one described here. In my case Visual Studio inserts using directives inside namespace and I want to prevent this. I did try to uncheck Resharper option:
Languages -> C# -> Formatting Style -> Namespace Imports -> Add using directive to the deepest scope
And it didn't help. Also I tried to temporary disable the Resharper. Still same issue.
Btw, I have StyleCop and StyleCop+ installed as well. Maybe it is causing the issue.
So right now when I go and Add New Item -> Class - it will create new code file with using directives inside namespace. How to change this?
Have you replace your class template file with one that has one or more using directives inside the namespace declaration? If so, you're probably seeing the result of an interesting bit of C# plugin behavior: a newly added using directive is placed after the last recognized using directly already in the file, regardless of where that is.

2 times the same project in the Class View Window (visual studio)

After converting a Web Site Project to a Web Application Project in Visual Studio, it seems that there is a problem with some meta data. The first noticeable is the fact that the project is mentioned twice in the Class View window.
If I add a new namespace and a new class in it, I'm not able to select it using intellisense. when I open the hierarchy of the Class view, I see my new namespace in one of them (that are indentical except the recent addings)
Is there a way to clean that up ?
You have to get rid off the App Folder. That's the origin of this problem.
http://vishaljoshi.blogspot.be/2009/07/appcode-folder-doesnt-work-with-web.html

adding visual studio XAML Intellisense to non-wpf classes

I have "DOM like" data structure in c# (parent, childNodes, properties, enums...) and I want to use xml\xaml file to some of the initializing. I already wrote a tool that transform my xaml to c# and inject them in the right place.
I want the exact Intellisense behavior of WPF except that my classes doesn't inherits from WPF base classes and my project in not wpf application on library and doesn't reference wpf assemblies. i also don't want to use xsd schema because classes are added and edited very frequently.
I'm using visual studio 2010
Is it possible?
Create a xaml (start by creating a resource dictionary and delete the content).
Add your own assembly as the default namespace and start using your types. I have created a test for sample data recently, here's how it looks like:
<MainViewModel xmlns="clr-namespace:MvvmTest.ViewModels.DesignTime"
Name="The design time main view model">
<MainViewModel.SubViewModels>
<FirstSubViewModel Name="The design time first sub-view model" />
<SecondSubViewModel Name="The design time second sub-view model" />
</MainViewModel.SubViewModels>
</MainViewModel>
You can load the file using the XamlReader class. As a bonus compared to xml, the file will be compiled and run time loading will be much faster.

asp.net MVC Base Controller error - Type Expected

Using VS 2010 and the latest version of ReSharper...
When I create a BaseController class I get the red squiggly stating the "Type is Expected". The project will still compile but I have not tried to run it yet.
See attached image.
Any ideas what causes this?
Close and reopen the file.

Resources