0

我正在尝试使用具有以下内容的 XamlReader 解析 XML 文件

    <Canvas xmlns:seic="clr-namespace:NameSpace1;assembly=Assembly1" 
    xmlns:seidm="clr-namespace:NameSpace2;assembly=Assembly2" 
    xmlns:seogptpi="clr-namespace:NameSpace3;assembly=Assembly3" 
    xmlns:seogdc="clr-NameSpace4;assembly=Assembly4" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Name="_99abfc59e3ad417d98db31591a6f9dd7" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    Canvas.Left="0" Canvas.Top="0" Tag="TemplatePart" Width="800" Height="600"  
    seogdc:FrameworkElementExtensions.Id="Canvas" 
    seogdc:FrameworkElementExtensions.ShowRotateCue="False" 
    seogdc:FrameworkElementExtensions.ShowPositionCue="False" 
    seogdc:FrameworkElementExtensions.IsSizeSerializable="False" 
    seogdc:FrameworkElementExtensions.IsTargetDimensions="False">
<Canvas x:Name="Canvas1" 
      Canvas.Left="0"    
      Canvas.Top="0" 
      Tag="TemplatePart" 
      Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Canvas}}, Path=Width}" 
      Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Canvas}}, Path=Height}" 
      Background="{x:Static Brushes.Black}"
      seogdc:FrameworkElementExtensions.Id="Canvas" 
      seogdc:FrameworkElementExtensions.ShowRotateCue="False" 
      seogdc:FrameworkElementExtensions.ShowPositionCue="False" 
      seogdc:FrameworkElementExtensions.IsTargetDimensions="False" 
      seogptpi:TemplateManager.IsMainPart="True"
      seogptpi:TemplateManager.TemplateName="Canvas">
<seic:DomainParameter.DomainModel>
  <seidm:StatelessDomainModel>
    <seidm:StatelessDomainModel.DomainFeatures>
      <seidm:ColorFeature LabelFillTransparency="0">
        <seidm:ColorFeature.FontBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.FontBlinkSetting>
        <seidm:ColorFeature.LineBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.LineBlinkSetting>
        <seidm:ColorFeature.FillBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.FillBlinkSetting>
      </seidm:ColorFeature>
    </seidm:StatelessDomainModel.DomainFeatures>
  </seidm:StatelessDomainModel>
</seic:DomainParameter.DomainModel>
  </Canvas>
</Canvas>

但它只是一直抛出一个 XamlParseException('Cannot set unknown member 'Namespace2.ColorFeature.LabelFillTransparency'.' Line number '13' and line position '31'.) 。我添加了对上述 4 个程序集的引用。出于隐私目的,我选择不提供确切的程序集名称。有人可以告诉我可能会发生什么吗?

提前致谢。

4

1 回答 1

0

您需要ParserContext为该XamlReader.Parse方法提供自定义。您应该分配该ParserContext.XamlTypeMapper属性以启用XamlParser以查找 XAML 中引用的类型。这些方面的东西:

var context = new ParserContext();
context.XamlTypeMapper = new XamlTypeMapper(
  new[] {
    Assembly.GetExecutingAssembly().GetName().Name,
    "Assembly1",
    "Assembly2",
    "Assembly3",
    "Assembly4",
  }
);
var element = (FrameworkElement) XamlReader.Parse(xaml, context);
于 2013-09-10T21:47:58.377 回答