Pergunta

I'm getting this error on my Windows Phone app:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll

This happens only after I've installed and added a reference to WPtoolkit in my application with the following line,

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

I get the error at the following line,

public MainPage()
{
    InitializeComponent();
}

What could be the issue and what is a possible fix for this?


ApplicationPage

<phone:PhoneApplicationPage
    x:Class="AmazingCaller.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    xmlns:MyApp="clr-namespace:AmazingCaller"

    mc:Ignorable="d"
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

XAML

<ListBox x:Name="ContactResultsData" Tap="ContactResults_Tap_1" ItemsSource="{Binding}" Height="600" Loaded="ContactResultsData_Loaded_1" Margin="10,0">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Margin="0, 20, 0, 0">
                <Border BorderThickness="2" HorizontalAlignment="Left" VerticalAlignment="Center" BorderBrush="{StaticResource PhoneAccentBrush}" Margin="5, 0, 0, 0">
                    <Image Source="{Binding Converter={StaticResource ContactPictureConverter}}" Width="48" Height="48" Stretch="Fill"  />
                </Border>
                <TextBlock x:Name="ContactResults" Text="{Binding DisplayName, Mode=OneWay}" FontSize="{StaticResource PhoneFontSizeLarge}" Margin="10, 0, 0, 0" />
            </StackPanel>
            <toolkit:ContextMenuService.ContextMenu>
                <toolkit:ContextMenu>
                    <toolkit:MenuItem Header="Test">

                    </toolkit:MenuItem>
                </toolkit:ContextMenu>
            </toolkit:ContextMenuService.ContextMenu>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Foi útil?

Solução

Here is a working proof:

File --> New Project --> New Databound Application (wp8) and here is the code:

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox x:Name="ContactResultsData" Tap="ContactResults_Tap_1" ItemsSource="{Binding Items}" Height="600" Loaded="ContactResultsData_Loaded_1" Margin="10,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0, 20, 0, 0">
                                <Border BorderThickness="2" HorizontalAlignment="Left" VerticalAlignment="Center" BorderBrush="{StaticResource PhoneAccentBrush}" Margin="5, 0, 0, 0">
                                    <Image Width="48" Height="48" Stretch="Fill" Source="/Assets/Tiles/FlipCycleTileSmall.png"  />
                                </Border>
                                <TextBlock x:Name="ContactResults" Text="{Binding LineOne, Mode=OneWay}" FontSize="{StaticResource PhoneFontSizeLarge}" Margin="10, 0, 0, 0" />
                            </StackPanel>
                            <toolkit:ContextMenuService.ContextMenu>
                                <toolkit:ContextMenu>
                                    <toolkit:MenuItem Header="Test">

                                    </toolkit:MenuItem>
                                </toolkit:ContextMenu>
                            </toolkit:ContextMenuService.ContextMenu>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </Grid>

Make sure that the method ContactResults_Tap_1 has the following signature:

private void ContactResults_Tap_1(object sender, System.Windows.Input.GestureEventArgs gestureEventArgs)
{
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top