尝试绑定加载的子类事件处理程序时发生XamlParseException

尝试绑定加载的子类事件处理程序时发生XamlParseException,xaml,events,windows-phone-8,loaded,Xaml,Events,Windows Phone 8,Loaded,在我的Windows Phone项目中,我遇到了同样的问题: 但是,我的处理程序似乎有正确的签名 更奇怪的是,我在另一个页面上对UIElement_Tap事件做了同样的事情,效果很好 MainPage.xaml <v:PageBase x:Class="PhoneApp1.Views.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:/

在我的Windows Phone项目中,我遇到了同样的问题:

但是,我的处理程序似乎有正确的签名

更奇怪的是,我在另一个页面上对UIElement_Tap事件做了同样的事情,效果很好

MainPage.xaml

<v:PageBase
    x:Class="PhoneApp1.Views.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:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:v="clr-namespace:PhoneApp1.Views"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ItemsControl Grid.Row="0"
                      Loaded="ItemsControl_Loaded"
                      Margin="0,0,0,120">

            <TextBlock Text="Item1"/>
            <TextBlock Text="Item2"/>
            <TextBlock Text="Item3"/>

        </ItemsControl>

        <ItemsControl Grid.Row="1"
                      Loaded="ItemsControl_Loaded"
                      Margin="0,120,0,0">

            <TextBlock Text="Item1"/>
            <TextBlock Text="Item2"/>
            <TextBlock Text="Item3"/>
            <TextBlock Text="Item4"/>

        </ItemsControl>

    </Grid>

</v:PageBase>
PageBase.cs

using Microsoft.Phone.Controls;

namespace PhoneApp1.Views
{
    // Common code across pages.
    public class PageBase : PhoneApplicationPage
    {
        protected virtual void ItemsControl_Loaded(object sender, System.Windows.RoutedEventArgs e    )
        {
            //...
        }
    }
}

我知道我可以重写该方法并在主页中调用基类型,但这违背了使用公共基的目的,不是吗?

这就是我最终解决此问题的原因: 为itemscontrol指定了一个名称,并将事件连接到主页构造函数中:


itemControl1.Loaded+=base.ItemsControl\u Loaded

尝试用EventArgs替换System.Windows.RoutedEventArgs

using Microsoft.Phone.Controls;

namespace PhoneApp1.Views
{
    // Common code across pages.
    public class PageBase : PhoneApplicationPage
    {
        protected virtual void ItemsControl_Loaded(object sender, System.Windows.RoutedEventArgs e    )
        {
            //...
        }
    }
}