目前我正在编译xaml
使用baml
. MarkupCompilePass1
除了指向baml/xaml
资源的相对路径之外,这工作得很好。例如,假设 xaml 文件位于目录ui/controls/test.xaml
中,则生成的代码 ( test.g.cs
) 应如下所示:
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/Sample01;component/ui/controls/test.xaml", System.UriKind.Relative);
#line 1 "test.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
但它目前看起来像这样:
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/Sample01;component/test.xaml", System.UriKind.Relative); // <--- Here is the problem
#line 1 "test.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
我该如何解决这个问题?不完整,Uri
因为它不包含/ui/controls
.
编辑 1
这是生成baml
和的当前代码*.g.cs
foreach (var _xaml in xamlSources)
{
// Relative path to the xaml file
_xaml.RelativePath = _xaml.RelativePath = Path.GetDirectoryName(_xaml.Path.Replace(CXUIBuildEngine.ProjectRoot, ""));
_task = new MarkupCompilePass1();
_task.BuildEngine = BuildEngine;
_task.RequirePass2ForMainAssembly = false;
_task.OutputType = "library";
// List of xaml to compile, im this case just one,
// because only one output is allowed so we have to set
// the specific output per compile process...
_task.PageMarkup = new[] { new XamlItem(_xaml.Path) };
// Set default namespace
if (!string.IsNullOrWhiteSpace(CXUIBuildEngine.RootNamespace))
{
_task.RootNamespace = CXUIBuildEngine.RootNamespace;
}
// Set default options
_task.AssemblyName = CXUIBuildEngine.AssemblyName;
_task.Language = "cs";
// !!! Here we combine the output path with the relative path,
// !!! This is maybe already the fault
_task.OutputPath = Path.Combine(TempOutputDirectory, _xaml.RelativePath);
// Add all references as XamlItem
if (CXUIBuildEngine.References != null)
{
_task.References = CXUIBuildEngine.References.Select(item => new XamlItem(item.Location)).ToArray();
}
if (!_task.Execute())
{
return false;
}
}
十分感谢!