简体   繁体   English

在类型'%1'中找不到可连接属性'%0'

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

I'm trying to load xaml using XamlReader.Load(xamlstring) in a PCL(for windows 8.1 & phone 8.1) project, but I'm always hitting the exception "Windows.UI.Xaml.Markup.XamlParseException" at the below line: 我正在尝试在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>";

And this is the namespace declaration 这是名称空间声明

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' ";

Any help to solve this issue? 对解决此问题有帮助吗? or What Im doing wrong? 还是我做错了什么?

EDIT: 编辑:

The Exact Xaml string I'm trying to load is 我要加载的确切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>

EDIT 2: 编辑2:

This is the stacktrace of the excepton 这是excepton的堆栈跟踪

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)}

EDIT 3: 编辑3:

The Exact Method: 确切方法:

 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;
            }
        }

The problem is that you were explicitly naming the assemblies in your XMLNS declaration. 问题是您在XMLNS声明中显式命名了程序集。 They were not the correct assembly references, so I just removed them: 它们不是正确的程序集引用,因此我删除了它们:

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'

That works. 这样可行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mahapps:在“ MetroWindow”类型中找不到可附加属性“ Flyouts” - mahapps:The attachable property 'Flyouts' was not found in type 'MetroWindow' 在“ ResourceDictionary”类型中找不到可附加属性“ ThemeDictionaries” - The attachable property “ThemeDictionaries” was not found in type “ResourceDictionary” 在“FontImageSource”类型中找不到可附加属性“触发器” - The attachable property 'Triggers' was not found in type 'FontImageSource' 在类型“ ResourceDictionary”中找不到可连接属性“ MergedDictionaries” - The attachable property 'MergedDictionaries' was not found in type 'ResourceDictionary' WPF密码绑定类型中找不到附加属性 - Attachable property not found in type with WPF Password Binding Mahapps.Metro:在MetroWindow类型中找不到可附加的属性WindowCommands - Mahapps.Metro : The attachable property WindowCommands was not found in type MetroWindow WPF电话8在DataTemplate类型中找不到可附加属性Resources - WPF phone 8 The attachable property Resources was not found in type DataTemplate 在“TabbedPage”类型中找不到可附加属性“ToolbarPlacement”。 [Xamarin.Forms] - The attachable property 'ToolbarPlacement' was not found in type 'TabbedPage'. [Xamarin.Forms] 在“样式”中找不到可附加的属性“触发器” - The attachable property Triggers was not found in Style 如何解决:在网格应用程序中的样式中找不到可附加属性触发器 - How to solve: the attachable property triggers was not found in style in a Grid Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM