I want to work with a DataGrid in Kaxaml. How do I reference the toolkit dll?
Copy WPFToolkit.dll to "C:\Program Files\Kaxaml\"
Restart Kaxaml
Now you can use such namespace:
xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
Another option would be to make a junction and add a probing path to Kaxaml's config.
Make Junction to code
run elevated cmd
cd "c:\Program Files (x86)\Kaxaml"
mklink /J ProbeFolder "c:\path-to-your-code"
Modify Kaxaml.exe.config
run elevated notepad
open "C:\Program Files (x86)\Kaxaml\Kaxaml.exe.config"
add the following to the <configuration>:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="ProbeFolder"/>
</assemblyBinding>
</runtime>
save the file
restart kaxaml
When mapping custom classes and namespaces in XAML using the clr-namespace/assembly notation, you can't specify the path of the assembly containing the class but just the assembly's name (more details can be found on MSDN), since all referenced assemblies must be linked during the XAML compilation via the project file.
Kaxaml doesn't support the concept of a project since it doesn't do any compilation but rather dynamically parses and renders the XAML entered in the editor "on-the-fly" by using the System.Windows.Markup.XamlReader class.
This means that when using Kaxaml you can only reference classes contained in the assemblies that are part of the .NET Framework.
Building on top of Todd White's solution (& this is future reference for myself too) your XAML in Kaxaml would reference a 3rd party library as follows:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxlc="clr-namespace:DevExpress.Xpf.LayoutControl;assembly=DevExpress.Xpf.LayoutControl.v13.2"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Layout Control Start -->
<dxlc:LayoutControl Orientation="Horizontal">
</dxlc:LayoutControl>
<!-- Layout Control End -->
</UserControl>
Related
I am following the basic starter example shown here:
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands
I have followed it as closely as I can. I can get it working if I put my user control in with the UWP app (different to the example) but not as it is with the usercontrol in the class library.
Firstly, when I run the example as it is, I get:
"WindowsXamlManager and DesktopWindowXamlSource are supported for apps targeting Windows version 10.0.18226.0 and later. Please check either the application manifest or package manifest and ensure the MaxTestedVersion property is updated."
The only solution I can find to this was to add a manifest file to the wpf project containing:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<maxversiontested Id="10.0.18362.0"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
After that, I did not see that error, but when the wpf form loads, I see "Cannot create control of type ClassLibrary1.MyUserControl1", but no clues as to why.
Anyone know what I am doing wrong, how to find out what the problem is of know of any examples that do work?
I downloaded your project package and I found that you missed a step.
It's the forth step in Create a custom UWP control
Before the closing element, add the following XML to disable several properties and then save the project file. These properties must be enabled to host the custom UWP control in a WPF (or Windows Forms) app.
<PropertyGroup>
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
</PropertyGroup>
After you add this code to ClassLibrary1.csproj, clean up the class library and rebuild it, then everything will work.
Best regards.
I have issues with Xamarin in Visual studio 2017 15.8.0 Preview 4 (And all previous builds)
I have a Xamarin forms project with a Android Project and a UWP project, if I change the startup project to UWP and try to compile I get this error
Error Failed to resolve assembly: 'FoosballXamarin.Android,
Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' FoosballXamarin.UWP ...\Views\LoginPage.xaml
And the XAML itself will give me errors on these lines
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels;assembly=FoosballXamarin.Android"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers;assembly=FoosballXamarin.Android"
And want me to change them to
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels;assembly=FoosballXamarin.UWP"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers;assembly=FoosballXamarin.UWP"
Is there a way to write it differently so I dont get this error every time?
Based on the errors you're seeing, I'm going to guess you have this configured as a shared project (not PCL/.netstandard). If that's the case, simplify the lines in the XAML file to:
xmlns:viewModels="clr-namespace:FoosballXamarin.ViewModels"
xmlns:helpers="clr-namespace:FoosballXamarin.Helpers"
In other words, just remove the assembly= part. If you don't specify the assembly on the xmlns line, it will assume the namespace is the same assembly as the XAML file. So you only need to include it if it's in a different assembly.
Since shared projects include the XAML file in multiple assemblies (one per platform), you pretty much have to omit the assembly= on the xmlns declaration for namespaces/types in the same assembly.
A Universal Class Library (UWP) project that I created has two classes;
1.
A public BoolToVisibilityConverter - an IValueConverter whose responsibility it is to convert a bool to a XAML Visibility, and vice-versa.
2.
A public CustomControl templated control whose template (defined in Themes\Generic.xaml (project structure below)) uses the BoolToVisibilityConverter mentioned above.
Its template looks like this;
<Border ...>
<Border.Resources>
<local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</Border.Resources>
<Grid ...>
<Grid ...
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Converter={StaticResource BoolToVisibilityConverter}}" />
</Grid>
</Border>
Value, the property the Visibility is bound to, is a boolean dependency property on the control, local being an alias to the namespace within which the BoolToVisibilityConverter resides (which is the same as that of the templated control).
Project Structure
Build Configurations
The Release build configuration of the project has the "XML documentation file" and "Generate library layout" options enabled.
Generating a NuGet package
The NuSpec for my project (located at NuGet\RefClassLibrary.nuspec) is;
<?xml version="1.0"?>
<package >
<metadata>
<id>RefClassLibrary</id>
<version>1.0.0</version>
<!-- various other metadata -->
</metadata>
<files>
<file src="..\bin\Release\**" target="lib\uap10.0"/>
</files>
</package>
The file was generated using the nuget.exe spec command, with the NuGet CLI version 4.3.0.4406.
To generate the NuGet package, I first deleted the bin and obj folders, and built the project in the Release (Any CPU) configuration, which generated the following structure in the bin folder,
I then generated the NuGet package for the class library using the command nuget.exe pack RefClassLibrary.nuspec from within the NuGet\ folder, which generated a nupkg file with the following structure,
Problem: Consuming the class library via the NuGet package
From within a new Universal Windows Application project I ran the Install-Package commmand with the absolute path to the nupkg as its argument, within the Package Manager Console within Visual Studio, which installed the generated package.
After building the project (without errors), I added the following XAML to a new Blank Page,
<Page ...
xmlns:rcl="using:RefClassLibrary">
<Grid ...>
<rcl:CustomControl Width="200" Height="200" Value="True"/>
</Grid>
</Page>
Which resulted in an error that reads,
XamlParseException: The text associated with this error code could not be found.
Cannot deserialize XBF metadata type list as 'BoolToVisibilityConverter' was not found in namespace 'RefClassLibrary'. [Line: 0 Position: 0]
StackTrace:
at Windows.UI.Xaml.Controls.Control.ApplyTemplate()
at Microsoft.VisualStudio.DesignTools.UwpDesigner.InstanceBuilders.WindowsUIXamlLocalInstanceManager.EnsureElementInDictionary(Object root, ViewNode knownAncestor)
InnerException: None
Upon viewing RefClassLibrary in the Object Browser, sure enough as the error suggests, the BoolToVisibilityConverter class wasn't there...
Consuming the class library directly
I used the Uninstall-Package RefClassLibrary command to remove the package from the project.
I then unzipped the nupkg file using the command 7z x RefClassLibrary.1.0.0.nupkg -oOut, which extracts it to a folder Out, and directly referenced the dll contained within the Out\lib\uap10.0\ folder within the project by adding a Reference via Solution Explorer, which made it work perfectly. The BoolToVisibilityConverter did show up in the Object Browser.
How should this issue be fixed?
The correct assembly gets included within the NuGet package, although some parts of it (?) don't get 'imported' into the project...
When a NuGet package is installed via the Install-Package Cmdlet, this is, as I understand, what NuGet does,
The identifier and version number of the package to be installed are retrieved. It does so via the specified arguments (in the case of a version number not being specified, it defaults to the latest 'stable' version), or by reading the contents of the package that it points to.
The .nupkg file and some other assets associated with the package are copied to and cached within the %USERPROFILE%\.nuget\packages\{identifier}\{version}\ folder.
The package is then extracted and installed within the Visual Studio project that you are in.
When you install the same version of the same package again, NuGet uses the cached files located within the aforementioned folder, instead of re-downloading them.
The problem described in the question originated as a result of me not incrementing the version number of the NuGet package.
I developed the library project in two steps on my machine,
I intially created the library project with only the CustomControl, generated the library package, and installed it in an external app project.
It was afterwards that I added the BoolToVisibilityConverter, re-generated the library package, and re-installed it in the app project.
The version number of the package (1.0.0) specified in the .nuspec file was not incremented between the first and second steps, and therefore the new package generated in step 2 was not used by NuGet because a package with the same identifier and version number was already cached at %USERPROFILE%\.nuget\packages\.
This would explain why it worked (refer to the comments on the question) for Sunteen Wu - MSFT (thanks!).
So, solution is to either,
Increment the version number in the .nuspec file, or,
Delete the folder that corresponds to the package (or version thereof), located within the %USERPROFILE%\.nuget\packages folder,
...after which you would re-generate the library package with the same version number, and install it in the app project.
I have multiple projects in my solution. Each project references other projects. The dlls are quite big and I don't want them to be included in the bin of every project that references it.
What are my options? Ideally I'd like to place them in one location and reference that without needing to include them in my bin folder for each project. The only location I can think of is the GAC. Are there any ideas/suggestions on how you have gotten around this?
Is it possible to use probing paths? Anyone used this before/point me to a tutorial?
I've tried probing paths, get an error when running the application, is this not set up correctly? I've placed my dlls I wish to load from this path in the C:\Projects\myProject\bin folder. And set copy to false in the reference
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="C:\Projects\myProject\bin"/>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
Thanks
I guess what you prefer, is turning off CopyLocal when referencing assemblies in Visual Studio
The steps could be:
Open Solution Explorer
Right click at the reference item (project or assembly)
Select Properties in the context menu.
Set CopyLocal to False (default is true)
Then the references won't be copied to your project\bin\debug or etc.
UPDATE
You still need to copy your dependency to the same folder, or GAC, or probing paths to run your application.
That is how .Net resolve the assemblies references.
You may refer to How the Runtime Locates Assemblies.
UPDATE 1
MSDN Specifying an Assembly's Location
Using the <probing> Element
The runtime locates assemblies that do not have a code base by probing. For more information about probing, see How the Runtime Locates Assemblies.
You can use the element in the application configuration file to specify subdirectories the runtime should search when locating an assembly. The following example shows how to specify directories the runtime should search.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
The privatePath attribute contains the directories that the runtime should search for assemblies. If the application is located at C:\Program Files\MyApp, the runtime will look for assemblies that do not specify a code base in C:\Program Files\MyApp\Bin, C:\Program Files\MyApp\Bin2\Subbin, and C:\Program Files\MyApp\Bin3. The directories specified in privatePath must be subdirectories of the application base directory.
You can add referenced libraries to the output folder of start up project only:
1) Right click on starting project, "Add", "Existing Item". Or [Shift]+[Alt]+[A] combination in VS2010 with defaults.
2) Change type selector to "All files (*)", find and select your library.
3) Change "Add" selector to "Add As Link" and press it.
4) Select a link just added to a project, and in Properties window set "Copy to Output Directory" to "Copy always". Now, each time you building the solution, this library will be copied to the output folder of your startup project.
5) If you want to restrict copying this dll to the output of project that uses it, right-click on reference in that project, and in Properties window set "Copy Local" to false.
Implications:
The only place where your referenced dll's will appear will be your start-up project's output directory.
Disadvantages:
If you'll change your start-up project, you'll need to add all the links to it again.
Start-up project directory in Solution Explorer becomes messy.
I'm trying to add a reference to the GAC version of System.Xml in a Visual Studio 2008 web site project. I right-click the project icon in the Solution Explorer, and click Property Pages. Under the References tree option, I click the 'Add' button on the right. I navigate to System.Xml in the .NET tab, and double click it (the Path it lists for System.Xml, C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.XML.dll, DOES exist). The dialog disappears, but... System.Xml does not get added as a reference! The list just stays the same.
I tried adding another .NET reference just to make sure others could be added OK, I added System.Web.RegularExpressions and it added fine. What on earth could be causing it not to add System.Xml?
Try to edit your vbproj file, and add
<Reference Include="System.Xml" />
I just created a ASP.NET Website with default language C# & .NET 2.0 as the target. I also observed that even if you try to add a reference to System.XML, you will not find one in the project proprieties page.
As far it goes for me, its as designed.
By default you can access all the default .NET namespaces (in your target version) by just adding "using NAMESPACE_NAME;" in you code behind.(System (& the sub namespaces like XML etc). ASP, Microsoft & MS) Only when you reference a third party .NET dll or something that's not default for an ASP.NET Website project (could not find the list of defaults on the net), then a new folder called bin is created & a copy of that dll is stored in it if it is not in GAC.
EDIT: Regarding not able to add a cs file to vb file, I just did that, & I could access System.Xml namespace in the vb file.
Well it looks like it might have had something to do with my trying to add a .cs file to a project where the rest of the files were in vb.net. Hmph, I thought one of the major benefits of .NET was you could easily mix languages. Oh well, I removed that and added these lines into my web.config file:
<add namespace="System.Xml"/>
and
<add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
and now it compiles OK. I can access System.Xml from within VB code, so it looks like I'll have to translate the class I had from C# to VB.net. Hmph.