I have a solution with two projects: a WPF sample application called "WPFSample" and a class library project called "ReferencedAssembly". "WPFSample" references "ReferencedAssembly".
The project "ReferencedAssembly" contains a couple of classes. Every class has its own namespace, i.e. "MyClassLibrary" or "MyClassLibrary.MyOtherTypes". A sample class with the namespace "MyClassLibrary" is called "Movie".
Now I want to map the .NET namespace to the XAML namespace using the URL "http://schemas.emmbee.de/". For this purpose I added the following lines to AssemblyInfo.vb in the "WPFSample" project and build it afterwards:
Imports System.Windows.Markup
<Assembly: XmlnsPrefix("http://schemas.emmbee.de/", "ra")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary.MyOtherTypes")>
In XAML I add the namespace definition like this:
<xmlns:ra="http://schemas.emmbee.de">
If I want to use the "Movie" class with
<ra:Movie/>
I receive the error, that the class "Movie" doesn't exists in namespace "http://schemas.emmbee.de".
If I instead add a namespace definition in this way:
<xmlns:ra="clr-namespace:ReferencedAssembly.MyClassLibrary;assembly=ReferencedAssembly">
all works fine.
What is wrong with the XmlnsDefinition?
I found it out.The Namespace mappings
Imports System.Windows.Markup
<Assembly: XmlnsPrefix("http://schemas.emmbee.de/", "ra")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary.MyOtherTypes")>
must be included in the "AssemblyInfo.vb" in the assembly "ReferencedAssembly", not in the assembly "WPFSample".
Related
I'm currently working on a WPF application that uses a plotting library called Live Charts for WPF. I want to save a PNG of my graph, which is described on their github page Save Plot Example also discussed at this stackoverflow question here. The problem is adding a reference to the windows base assembly.
`
private void SaveToPng(FrameworkElement visual, string filename)
{
var encoder = new PngBitmapEncoder();
EncodeVisual(visual, filename, encoder);
}
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
{
var bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
//bitmap.Render();
bitmap.Render(visual);
var frame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(frame);
using (var stream = File.Create(fileName)) encoder.Save(stream);
}
`
I have tried to add this dll as a reference which is located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0, but when I do this it does not work. It is actually implicitly included in the project, so that may be why I can add it explicitly like I did with the PresentationCore.dll and PresentationFramework.dll which were also required and solved a few errors. The error states: the type 'System.Windows.Freezable' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. This is shown by hovering over the call to bitmap.Render(visual), and when hovering over encoder.Save(stream) as shown in the picture and in the above code. I believe resolving this dependency would fix the problem, but I cannot figure out how. Thank you.
Picture of Project
Discovered what I believe is the answer to the problem. I was creating the SaveToPNG and EncodeVisual methods inside of a class library which would be used in the WPF project. The class library is unable to accept WindowsBase as an explicit reference, but the WPF project itself can. It will take some restructuring of the code to implement this in the WPF project itself, but it seems to be the way to resolve this problem.
I am using .NET 6. Here is the contents of my csproj file in my class library:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<Compile Update="Core Library\Port.cs">
<SubType>Component</SubType>
</Compile>
</ItemGroup>
</Project>
I did not see the attributes that you spoke of, and autocomplete could not reference them in this file. Inside of the IDE (Rider) I was able to target net6.0-windows in the properties menu of the project. I then reinserted the code into the class library, but the same error still occurred. I agree with you that it shouldn't be necessary to reference WindowsBase, which isn't necessary when placing the code in the wpf project itself, but in the class library I also had to reference PresentationCore and PresentationFramework, which did take care of multiple errors.
I've created a new converter with the following structure:
package com.mycompany;
#Converter
public final class MyCustomConverter {
#Converter
public static TypeB convert(TypeA typeA) {
// do the conversion
}
}
I've also created in my src/main/java/resources folder the following package, META-INF.services.org.apache.camel and within that a TypeConverter file which just says:
com.mycompany
Within my route from TypeA I have got:
<convertBodyTo type="com.mycompany.TypeB" />
Yet my tests constantly fail to pick up the file and thus cannot find the converter, with the exception being:
Caused by: org.apache.camel.NoTypeConversionAvailableException: No
type converter available to convert from type: com.mycompany.TypeA to
the required type: com.mycompany.TypeB with value TypeA[value1="blah"]
Am I meant to do something else to get my test to pick up the TypeConverter file? Surely putting it in that resources folder with the exact structure adds it to the classpath and so it would be accessible.
Its recommended in the TypeConverter file to list the FQN of all the type conveters, eg
com.mycompany
Should be
com.mycompany.MyCustomConverter
This is also what we say on this page: http://camel.apache.org/type-converter.html
And could you check inside the generated JAR file of yours, that the META-INF/services/org/apache/camel directory is there, and that the TypeConverter file is present (and it is not in some directory like META-INF/org.apache.camel).
Also what is the runtime environment you use? Do you run Camel standalone, Tomcat, OSGi or something else?
I would like to experiment with map features in Saxon (http://www.saxonica.com/documentation/expressions/xpath30maps.xml), but I am unable to get past query compilation. Maybe I am missing some parameter or I use a wrong namespace, but I just can't find the right answer. This is my query code:
xquery version "3.0";
(: i have also tried http://www.w3.org/2005/xpath-functions/map, no difference :)
import module namespace map = "http://ns.saxonica.com/map";
map:get(map { 1 := 'aaa'}, 1)
invoked from command line:
"c:\Program Files\Saxonica\SaxonEE9.4N\bin\Query.exe" -s:play.xml -q:play2.xq" -qversion:3.0
The commands ends with error Cannot locate module for namespace "http://ns.saxonica.com/map"
When I leave out the module namespace map declaration, the error is Prefix map has not been declared, so I assume it must be.
Michael Kay has just posted a new blog entry with details on the Saxon Map implementation:
http://dev.saxonica.com/blog/mike/2012/01/#000188
You should use declare namespace instead of import module namespace for access to builtin functions. As far as I understand it, module import is for user-supplied modules only.
File map.xq:
declare namespace map="http://www.w3.org/2005/xpath-functions/map";
map:get(map { 1 := 'aaa'}, 1)
Works just fine:
> "C:\Program Files\Saxonica\SaxonEE9.4N\bin\Query.exe" -qversion:3.0 map.xq
<?xml version="1.0" encoding="UTF-8"?>aaa
I tried it with Saxon-EE 9.4.0.2J (the Java version) too, with the same effect.
Dunno if this helps, but the BaseX XQuery Processor also offers an implementation of Michael Kay's map proposal (still to be finalized by the W3): http://docs.basex.org/wiki/Map_Module
In XAML-file of the SquadView page (VfmElitaSilverlightClientView.Pages.SquadView) I am using custom value converter. XAML-file is in "VfmElitaSilverlightClientView" namespace. Separate folder was created for converter and it is in "VfmElitaSilverlightClientView.Converter" namespace (in the same assembly). To use converter following code is used in XAML:
xmlns:Converter="clr-namespace:VfmElitaSilverlightClientView.Converter"
...
<NavigationControls:Page.Resources>
<Converter:BooleanToVisibilityConverter x:Key="resourceBooleanToVisibilityConverter" />
</NavigationControls:Page.Resources>
All works fine. Here I want to move converter class into a custom separate assembly "SilverlightCommonView" and class himself will be in "SilverlightCommonView.Converter" namespace. The XAML code is changed to the following:
xmlns:Converter="clr-namespace:SilverlightCommonView.Converter;assembly=SilverlightCommonView"
...
<NavigationControls:Page.Resources>
<Converter:BooleanToVisibilityConverter x:Key="resourceBooleanToVisibilityConverter" />
</NavigationControls:Page.Resources>
In this case when application throws following exception:
An unhandled exception ('Unhandled
Error in Silverlight Application...
Code: 4004 Category:
ManagedRuntimeError Message:
Microsoft.Practices.Unity.ResolutionFailedException:
Resolution of dependency failed, type="VfmElitaSilverlightClientView.Pages.SquadView",
name="(none)".
Exception occurred while: Calling constructor
VfmElitaSilverlightClientView.Pages.SquadView(). Exception is: XamlParseException -
The type 'BooleanToVisibilityConverter' was not found because
'cl...:SilverlightCommonView.Converter;assembly=SilverlightCommonView'
is an unknown namespace.
It's unclear why specified namespace is unknown (those assembly is referenced by the current one).
Please advise.
Any thoughts are welcome.
I'd bet you do not have an assembly reference to your shared/common project from your application project.
I want to run my wpf application "A" from another assembly "B".
I use the following code:
static void main()
{
var app = new A.App();
app.InitializeComponent();
app.Run();
}
when i run my app I got the following error:
Cannot convert string '/Resources/icon.gif' in attribute 'Icon' to object of type 'System.Windows.Media.ImageSource'. Cannot locate resource 'resources/icon.gif'. Error at object 'MainWindow' in markup file 'A;component/shell/shellview.xaml'.
How can I transfer from B images and resources info to A?
Thanks!
Are you using the Pack URI?
You can use the pack URI syntax to access resources embedded in other assemblies. The following example demonstrates the basic pack URI syntax for accessing embedded resources in other assemblies:
pack://application:,,,/;component//
Thus, if you wanted to locate a file named myPic.bmp in the folder myFolder in another assembly named myAssembly, you would use the following pack URI:
Pack://application:,,,/myAssembly;component/myFolder/myPic.bmp
As with other pack URIs, if the embedded file does not exist within a folder, the folder is omitted in the URI.
TRy using something like this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="CustomControls.Controls;component\Themes/...."
/>
</ResourceDictionary.MergedDictionaries>
Today I had the same problem, and I solved it by putting just:
Source="../../Resources/name.jpg"