在类型“%1”中找不到可附加的 属性“%0”

The attachable property '%0' was not found in type '%1'

我正在尝试在 PCL(对于 windows 8.1 和 phone 8.1)项目中使用 XamlReader.Load(xamlstring) 加载 xaml,但是我'我总是在下面的行中遇到异常 "Windows.UI.Xaml.Markup.XamlParseException"

string content = "<interactivity:Interaction.Behaviors>   
                    <core:EventTriggerBehavior EventName='Tapped'>
                      <core:InvokeCommandAction Command=
                         '{Binding ElementName=ViewControlGrid,
                          Path=DataContext.ViewActionClickCommand}'
                        CommandParameter='{Binding RecordId}' />
                    </core:EventTriggerBehavior>
                </interactivity:Interaction.Behaviors>";

这是命名空间声明

private static string namespaceString = 
       @"xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
        xmlns:core='using:Microsoft.Xaml.Interactions.Core;assembly=Microsoft.Xaml.Interactions' 
        xmlns:interactivity='using:Microsoft.Xaml.Interactivity;assembly=Microsoft.Xaml.Interactions' ";

对解决这个问题有什么帮助吗?或者我做错了什么?

编辑:

我要加载的确切 Xaml 字符串是

    <DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:core="using:Microsoft.Xaml.Interactions.Core;assembly=Microsoft.Xaml.Interactions" xmlns:interactivity="using:Microsoft.Xaml.Interactivity;assembly=Microsoft.Xaml.Interactions" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <StackPanel Margin="0, 0, 0, 1" Background="#FFFFFFFF">
      <interactivity:Interaction.Behaviors>
         <core:EventTriggerBehavior EventName="Tapped">
            <core:InvokeCommandAction Command="{Binding ElementName=ViewControlGrid, Path=DataContext.ViewActionClickCommand}" CommandParameter="{Binding RecordId}" />
         </core:EventTriggerBehavior>
      </interactivity:Interaction.Behaviors>
      <Grid Width="{Binding ActualWidth, ElementName=ThisStackPanel}" Height="92.5">
         <Grid Width="55.5" Height="55.5" HorizontalAlignment="Left" Margin="18.5, 18.5, 0, 0" VerticalAlignment="Top" Background="#FFFFFFFF">
            <Button Margin="0" Content="{Binding DisplayValues[0]}" Foreground="#FF000000" Command="{Binding ElementName=ViewControlGrid, Path=DataContext.ViewActionClickCommand}" CommandParameter="Image" Style="{StaticResource ButtonNoStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" />
         </Grid>
         <Grid Width="259" Height="92.5" HorizontalAlignment="Left" Margin="92.5, 0, 0, 0" VerticalAlignment="Top" Background="#FFFFFFFF">
            <Button Margin="0" Content="{Binding DisplayValues[1]}" Foreground="#FF000000" Command="{Binding ElementName=ViewControlGrid, Path=DataContext.ViewActionClickCommand}" CommandParameter="" Style="{StaticResource ButtonNoStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" />
         </Grid>
      </Grid>
   </StackPanel>
</DataTemplate>

编辑 2:

这是异常的堆栈跟踪

The attachable property '%0' was not found in type '%1'. [Line: 3 Position: 379]
   at Windows.UI.Xaml.Markup.XamlReader.Load(String xamlstring)
   at MyNamespace.MyProject.MyFolder.DataTemplates.TemplateConstructor.GetDataTemplateRow(List`1 zcRows, Boolean isPadding)}

编辑 3:

确切方法:

 public static DataTemplate GetDataTemplateRow(List<ZCRow> zcRows , bool isPadding = false)
        {

            string rowsXaml = "<StackPanel Margin = '" + GetCardMargins(isPadding) 
                + "' Background='#FFFFFFFF' >";
            //template.

            rowsXaml += @"<interactivity:Interaction.Behaviors><core:EventTriggerBehavior EventName='Tapped'><core:InvokeCommandAction Command='{Binding ElementName=ViewControlGrid, Path=DataContext.ViewActionClickCommand}' CommandParameter='{Binding RecordId}' /></core:EventTriggerBehavior></interactivity:Interaction.Behaviors>";

            foreach(ZCRow row in zcRows)
            {
                rowsXaml += GetRowXaml(row);
            }
            rowsXaml += "</StackPanel>";

            string xaml = @"<DataTemplate " + namespaceString + "  >" + rowsXaml + "</DataTemplate>";
            Debug.WriteLine("Datatemplate is " + xaml);
            try
            {
                return (DataTemplate)XamlReader.Load(xaml);
            }
            catch(Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                return null;
            }
        }

问题是您在 XMLNS 声明中明确命名了程序集。它们不是正确的程序集引用,所以我只是删除了它们:

xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
  xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' 
  xmlns:core='using:Microsoft.Xaml.Interactions.Core' 
  xmlns:interactivity='using:Microsoft.Xaml.Interactivity'

有效。