0

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>
Community
  • 1
  • 1
painotpi
  • 6,894
  • 1
  • 37
  • 70
  • Something's up with your xaml file. Try debugging where exactly your issue lies in the XAML – Sahil Mittal Sep 08 '13 at 06:47
  • How do I debug a `xaml` file? The only thing I've added is that line, and it's reference in the solution. Works fine if not for those. – painotpi Sep 08 '13 at 07:15
  • that's strange actually. Are you sure you are not having any other toolkit installed? because I can send you 10 projects that reference that file with no exception. Check you XAML closer or provide the code for it (.xaml and .cs) – George Nikolaides Sep 09 '13 at 04:08
  • @GeorgeNikolaides yes, I'll put up the code in a while :) cheers – painotpi Sep 09 '13 at 15:07
  • @GeorgeNikolaides Updated, please have a look. – painotpi Sep 09 '13 at 18:21
  • I have tested your code on a new windows phone 8 empty project and everything works fine. the only thing that i deleted from your xaml is the converter for which you didn't provide a code – George Nikolaides Sep 09 '13 at 21:35
  • @GeorgeNikolaides Can you check this --> https://github.com/d3athR0n/AmazingCaller/ – painotpi Sep 10 '13 at 16:57

1 Answers1

1

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)
{
}
painotpi
  • 6,894
  • 1
  • 37
  • 70
George Nikolaides
  • 1,386
  • 12
  • 21
  • Thanks for your time on this, I am on windows 8.1 and VS Express for windows phone. Does win 8.1 have any bearing on this? I'm putting my app on github, I'll post a link to you in a while – painotpi Sep 10 '13 at 08:58
  • 1
    At home I am using win8 with VS12 ultimate and on laptop win 8.1 with vs12 and both are ok with the example I gave. let me test git code – George Nikolaides Sep 10 '13 at 16:59
  • Cheers mate, thanks a ton for your time on this, I'm a complete novice with wp and c# btw. – painotpi Sep 10 '13 at 17:02
  • It seems like the problem lies under the signature of the `ContactResults_Tap_1` method. It is wrong. I have edited the answer and added the correct signature. Always use visual studio to automatically create this kind of methods/handlers. Also check out this [tool](http://visualstudiogallery.msdn.microsoft.com/3a96a4dc-ba9c-4589-92c5-640e07332afd) - i highly recommend using it – George Nikolaides Sep 10 '13 at 17:10
  • `Microsoft.Phone.Controls.GestureEventArgs` should be `GestureEventArgs`? That's the only thing? Because, removing the `Microsoft.Phone.Controls` gives me an error --> 'GestureEventArgs' is an ambiguous reference between 'System.Windows.Input.GestureEventArgs' and 'Microsoft.Phone.Controls.GestureEventArgs' – painotpi Sep 10 '13 at 17:18
  • it should be `System.Windows.Input.GestureEventArgs` not `Microsoft.Phone.Controls.GestureEventArgs`. fixed the answer again to be specific. - productivity tools will save you from troubles like this! – George Nikolaides Sep 10 '13 at 17:23