Missing xaml.xr of a class library file in UWP - xaml

I have a class library project which I am using in a UWP project. If I add any usercontrol xaml file in the class library and build it it builds fine. But the UWP project gives an error that it cannot find the .xr file.
Do I need to add the .xr file externally in any folder to my UWP project?

Yeah, for a class library with XAML files, if we want to reference the dll in other project, we need not only the dll itself but also the .xr.xaml file and some other files. Because in UWP environment, the resources are no longer embedded in the assembly but are placed next to the dll as content. See the similar case: How to add xbf files to visual studio project.
The files we need to reference like following:
ClassLibrary1(Class Library name) Folder
ClassLibrary1.xr.xml
UserControl.xaml (UserControl XAML file)
ClassLibrary1.dll
ClassLibrary1.pri
To get these files, we can check the "Generate library layout"
option in the Build configuration under the project's Properties page.
Then we can copy these files to anywhere and the UWP project just need to add reference to the ClassLibrary1.dll file in the Visual Studio, Visual Studio will automatically pick these files up and put them in the appx package when it builds the app.

Related

how to configure visual studio 2022 C++ project to redirect Dlls

I currently have an application under visual studio 2022, which uses the openworld_470.dll library
the app is working properly.
I would now like in the application to create a libs directory containing the openworld_470.dll libraries
the application no longer works when I move the libraries from the root of the application to the libs directory.
Do you have an idea to solve this linkage problem which seems simple at the base?
I added in the project configuration in the VC++ directories -> references directory $(CommonExecutablePath)\libs;
it still does not work.
By adding in the system PATH the path of my application/libs the app works but I don't have to modify the PATH.
The easiest option is to use SetDllDirectory to add the libs directory to your search path.
And then to set the loading of openworld_470.dll to be delayed. You can do this by adding /DELAYLOAD:openworld_470.dll to your linker settings.

frame.navigate to a page in different .dll

I have a Page class in a project A. I want to navigate to this page from my Universal windows project(say Project B) page. In UWP I am trying to achieve this using Frame.Navigate(typeof(Page_classA)), since NavigationService.Navigate(new Uri()) is obsolete in UWP.
But I get a Windows.UI.Xaml.Markup.XamlParseException in this case.
Is there any other way in UWP or metro Apps for navigating to a page in different assembly?
We can use Frame.Navigate(TypeName) method to navigate to a page in different assembly.
For example, we can create a Class Library(Universal Windows) named "ProjectA" and in this project add a new Page named "PageA". Then in this project's Properties page, check the "Generate library layout" option in the Build configuration.
In WinRT environment, the resources are no longer embedded in the assembly but are placed next to the dll as content. So we need to generate library layout so that we can reference the dll in other project conveniently.
After this, we can build the project and we will get following layout in "Debug" folder:
In ProjectA folder, it contains .xaml file and .xr.xml file:
When we get the library output files, we can copy them to anywhere and in the Universal Windows Project(Project B), we just need to add reference to the "ProjectA.dll" file. Visual Studio will automatically pick these files up and put them in the appx package when it builds the app.
And in Project B, we can use following code to navigate to PageA:
Frame.Navigate(typeof(ProjectA.PageA))
In your case, you get a Windows.UI.Xaml.Markup.XamlParseException, this may be that the .pri file is missing when you add the reference. Here is a similar case. So please check your library layout and make sure these resources are are placed next to the dll you referenced.

How to create a dll like shell32.dll which contains Icons

I am working on the Visual studio 2010. want to create a dll which contains icons just like shell32.dll. Can anyone guide me what I need to do.
Purpose : I just want my fav icons bind with one dll and keep in my root drive and customize me all folder icons and I just need it ot contain Dll thats it.
I have not idea what and all efforted is needed, I am ready to put how much effort is needed.
Any suggestion or comment is welcome.
I am not sure what detail is need so adding the picture of shell32.dll.
You can create a Resource-Only DLL.
From the link:
To create a resource-only DLL, you create a new Win32 DLL (non-MFC)
project and add your resources to the project.
Select Win32 Project in the New Project dialog box and specify a DLL project type in the Win32 Project Wizard.
Create a new resource script that contains the resources (such as a string or a menu) for the DLL and save the .rc file.
On the Project menu, click Add Existing Item, and then insert the new .rc file into the project.
Specify the /NOENTRY linker option. /NOENTRY prevents the linker from linking a reference to _main into the DLL; this option is
required to create a resource-only DLL.
Build the DLL.

Deploy SL4 application with localized DLL imports

I have a VS2010 SL4 project which uses an external Silverlight DLL. The project is localized with multiple RESX files, and the DLL is, too. I usually include external DLLs in my solutions as follows:
1) create a set of virtual folders in my solution like (say the imported DLL is named Sample.dll):
/Lib/Sample/Debug
/Lib/Sample/Release
2) create the same folders structure in the file system and copy under Debug and Release the respective versions of the DLL, so that now I find the following files:
/Lib/Sample/Debug/Sample.dll
/Lib/Sample/Release/Sample.dll
3) add to all the client projects in the solution a reference to /Lib/Sample/Debug/Sample.dll.
4) open the .csproj file of each project with the added reference, and change the Debug part of the path with $(Configuration), so that the right Debug/Release version is picked during build.
Now the question is: in my SL4 solution I can follow the same procedure for importing the language-neutral DLL. But what about its satellite resources? For instance, the French version of the imported DLL is built under subfolder fr-FR and named Sample.resources.dll. How should I include it correctly? Even If I try to manually add it in the compiled XAP under folder fr, it is ignored and the application falls back to its neutral culture...
I think I found it, here's a recap for whom may be interested:
open the .csproj file and ensure you add all your desired languages (separated by semicolons) in . For instance, if you support fr-Fr add <SupportedCultures>fr-Fr</SupportedCultures>.
(had to do this manually, I supposed 1. should be enough): once compiled, open your xap (rename it to .zip and open) and add if not present an element like <AssemblyPart Source="fr-FR/Sample.resources.dll" /> for each imported satellite with resources.
Thanks anyway!

How to create a Silverlight class library that is downloaded once, like an assembly

I have a website solution that contains three different Silverlight 4 projects, and they all make use of the same Silverlight class library.
I have done this by creating a class library project within the solution, and referencing it from the other Silverlight projects.
BUT the class library is included in every one of the XAPs. The user could end up downloading the same class library multiple times.
How do I canvert the class library into a XAP that can be downloaded once, in the same way that an assembly is?
(And why isn't there a Silverlight Assembly project type in Visual Studio?)
You should use Assembly Caching - it's a way to leave dependent assemblies out of your xap file. Instead you need to deploy them with your xap file by placing them in a seperate zip file in the same folder.
In the properties window of your Silverlight application you can choose to enable Assembly Library Caching. That will automaticly generate a zip file for each cacheably assembly.
In the project References folder in Visual Studio, select the referenced dll that you don't want to be loaded again, and in the Properties window set its Copy Local property to false.