-1

目前我正在编译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;
    }
}

十分感谢!

4

1 回答 1

0

在/中设置Linkand似乎有帮助:LogicalNameXamlPagesItems

var _item = new XamlItem(_xaml.Path);
_item.SetMetadata("Link", _xaml.RelativePath + "\\" + Path.GetFileName(_xaml.Path));
_item.SetMetadata("LogicalName", _xaml.RelativePath + "\\" + Path.GetFileName(_xaml.Path));
_task.PageMarkup = new[] { _item };

此属性仅保存在Dictioary<string, string>项目的内部。

于 2016-05-10T06:26:23.480 回答