I'm trying to embed a XAML file as a resource of my C++/CLI project (Using DevStudio 2005). I found few ways to do it but none of them is working properly.
Method 1. Embed it as a native resource
I used the .rc file to include the .xaml. I can easily load it using the native Win32 calls. Problem: the project is not recompiled if I change the xaml file.
Method 2. Embed it using the linker
I used the linker option "Embed Managed Resourcfe File" and added my xaml file there. I can easily use GetManifestResourceStream() after to load it. Problem: the project is not recompiled if I change the xaml file.
Method 3. Embed it using "Add Existing Item"
I tried to add the xaml file using "Project->Add->Existing Item" and then open my xaml file. Problem: When I popup the xaml file properties, I cannot find any "Build Tool" to compile/embed it. Can I get it from somewhere? Is there a command line I can use as a custom build step?
Method 4. Embed it using a .resx file
I tried several things but I never managed to load it at runtime using GetResourceStream(). For this one I would need a step-by-step procedure.
Can someone please tell me which method I should be using?
Related
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.
How to install the Gzip framework in swift 3.0.1 and also how to use it in swift 3 and iOS 10.
For This actually they given the following instructions like
1.Build Gzip framework.
2.In Build Phases, add Gzip.framework library to your project.
3.import Gzip in your Swift file.
4.Use in your code.
But among all steps How to implement the 1st step like building the Gzip framework.
Thanks in advance.
1.For the solution, Just download the project from the GitHub and then open it.
2.Now in the project navigator panel expand the folder named "product".
3.In that folder beneath you can see the Gzip.framework in red color, on that you right click in order to see it in the Finder.
4.From that Finder location, you just drag and drop into your project.
5.In General tab under linker and binaries you add the framework.
6.And finally import the header module like "import GZip"for required class and then implement the required things.
I am trying to create a Xamarin.Android Component to send to the Xamarin Component Store, and I need to bundle my Colors.xml with it, so it is accessible to everyone using my component. I am setting the build action for the Colors.xml tp "AndroidResource".
So I created an Android sample application, when I add a reference to my library project's dll, I am able to use the colors defined, my project compiles and it runs, but I get no intellisense on Xamarin Studio. So that would be a bad thing for anyone using my library, as they would not be able to even see that the colors are available to use. You can see in this picture the colors defined are not available in the suggestions box.
If I add the Colors.xml directly into my project, I get Intellisense support, like this:
Is there a way to achieve the same result above when adding just the dll reference? Did I do something wrong or Xamarin.Android/Xamarin Studio doesn't support this kind of scenario?
EDIT: To be clear, I know this is a problem with Intellisense not being able to pick up the values, but is there anything I can do to make it work?
I'm working on a unique project in that I would like to be able to have CSHTML Razor Views, Windows Forms, and various other "non project type crossing" project item templates in one single project in visual studio.
Is there a way I can override the project type so that it compiles as a Windows Form's project but still allows me to add CSHTML files and other template types to it?
When you edit the .csproj using notepad or an xml editor you'll find that <ProjectTypeGuids> element.
You can then edit it to have an entry like below
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Note: these are Guids from a portable class library project. You need to find correct ProjectTypeGuids for your requirements and add it.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d9d05cdc-96a1-4044-95d8-a4f8885a660a/what-is-the-significance-of-projecttypeguids-tag-in-the-visual-studio-project-file?forum=vsx
In a visual studio project I have three layers, Data Layer, Business Layer and Presentation Layer.
In the Data Layer I have a few XSLT's that transform some objects into an email, all works fine but I have discovered that the XSLTs do not get built/copied when building.
I have currently, created a folder in the deploy location and placed the XSLT's there but I am concerned about relying on a manual process to update these.
Has anyone encountered a similar issue and if so how did they get around it.
It smacks of changing the MSBuild script to copy the build artifacts to the required location, does anyone have examples of this?
Thaks
If you are using Visual Studio 2005/2008, the easiest way to do this is by including your XSLT files as project resources.
Open the Properties for your project.
Select the Resources tab. You will probably see a link that says "This project does not contain a default resources file. Click here to create one." Go ahead and click on that.
Click the Add Resource drop-down near the top and select Add Existing File.
Browse to your XSLT files and select them.
After you have done this, you can easily access the resources in the following manner:
// To get the contents of the resource as a string:
string xslt = global::MyNamespace.Properties.Resources.MyXsltFile;
// To get a Stream containing the resource:
Stream xsltStream = global::MyNamespace.Properties.Resources.ResourceManager.GetStream("MyXsltFile");
If you are using Visual Studio 2003, your best bet is to include those XSLT files as embedded resources for the DLL. In Visual Studio, select the file(s) in Solution Explorer, open the Properties pane, and change the Build Type to "Embedded Resource". You can then use the GetManifestResourceStream method to get a Stream containing the XSLT(s). The name to pass will be based on the default namespace of your assembly, the folder containing the file, and the name of the file.
For example, say your data layer assembly has a default namespace of My.DataLayer. Within your data layer project you have a folder named Templates which contains a file called Transform.xslt. The code to get your XSLT would look like this:
// There are numerous ways to get a reference to the Assembly ... this way works
// when called from a class that is in your data layer. Have a look also at the
// static methods available on the Assembly class.
System.Reflection.Assembly assembly = (GetType()).Assembly;
System.IO.Stream xsltStream = assembly.GetManifestResourceStream("My.DataLayer.Templates.Transform.xslt");
For more information check out this article on CodeProject.
Obvious question maybe, but still has to be asked, did you include the folder containing the XSLT's in the project itself? Is this a web or forms app?
In VS, it is easy to set the properties of the XSLT files in the project to copy on build, by default they do not.
I may have explained myself poorly.
THe Data layer is a class library that a the presentation layer references.
On building the DataLayer I can get the XSLTs to output to the Bin directory of the DataLayer. However when I build and publish the presentation layer, it correctly grabs the DLL but not the XSLTs