[英]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.