Я пытаюсь загрузить xaml с помощью XamlReader.Load(xamlstring)
в PCL (для Windows 8.1 & phone 8.1), но я всегда исключаю исключение "Windows.UI.Xaml.Markup.XamlParseException"
в строке ниже:Прилагаемое свойство '% 0' не найдено в типе '% 1'
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' ";
Любая помощь, чтобы решить эту проблему? или Что я делаю неправильно?
EDIT:
Точные 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:
Это StackTrace из 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:
Точный метод:
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;
}
}
Что произойдет, если вы попытаетесь разобрать строку 'string =" interactiveivity: Interaction.Behaviors> "', например? –
Oliver
@Oliver такое же исключение возникает. – MohanRajNK
Можете ли вы показать точный код, который используете? Два фрагмента именуют переменные 'content' и' namespaceString', но в вашем вопросе упоминается 'xamlString'. –