c# - Cannot compile project when declaring a XAML Resource Dictionary in code -
i've got resource dictionary
called editorresources.xaml , contains following code:
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:editors="clr-namespace:mycompany.editors"> <datatemplate x:key="passwordeditordatatemplate"> </datatemplate> </resourcedictionary>
but when include line of code in class:
private editorresources res = new editorresources();
it doesn't compile project. doesn't display errors list
view in .net ide
when @ output
view, displays following error:
error cs0246: type or namespace name 'editorresources' not found (are missing using directive or assembly reference?)
but, don't believe reference missing both resource dictionary , class in same project (same level) , can see editorresources
type highlighted type
, intellisense
kicks in expected when hit '.' key , displays properties relevant resource dictionary
i.e. .mergedictionaries
, etc...
update:
if me, you've stored resource dictionary (editorresources.xaml) in sub-folder (editors), , assembly called 'mycompany.activity.shared' example, don't forget include sub-folder in component's part when call code provided @drewnoakes, can call following without problems:
var res = new resourcedictionary { source = new uri("/mycompany.activity.shared;component/editors/editorresources.xaml", urikind.relativeorabsolute) };
once have object, can access datatemplates or other via code.
seems have editorresources.xaml
file not corresponding editorresources.xaml.cs
file.
in case, type xaml file defines resourcedictionary
. if wish have subclass of that, need define partial backing class , add relevant attributes in xaml link them together.
if don't need c# code behind scenes, load resourcedictionary
directly.
some code might help:
var dict = new resourcedictionary { source = new uri("/yourassemblyname;component/editorresources.xaml", urikind.relativeorabsolute) }
Comments
Post a Comment