1

I am having these same problems in my Windows Phone Project:

XamlParseException when adding event handler in XAML

http://social.msdn.microsoft.com/Forums/vstudio/en-US/7624b2fc-0dea-415f-a71d-1739020d9d2e/xamlparseexception-when-trying-to-bind-subclass-loaded-event-handler?forum=wpf

A

B

However, it seems like my handler does have the correct signature?

Even stranger, I did the same thing with the UIElement_Tap event, in another page and it works fine.

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>

MainPage.xaml.cs

namespace PhoneApp1.Views
{
    public partial class MainPage : PageBase
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
    }
}

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    )
        {
            //...
        }
    }
}

I know I could override the method and call the base type in my MainPage, but that defeats the purpose of having a common base, no?

4

2 回答 2

0

这就是我最终解决此问题的方法:为 itemscontrol 命名并在 MainPage 构造函数中连接事件:

itemControl1.Loaded += base.ItemsControl_Loaded;

于 2014-04-08T23:02:28.467 回答
0

尝试用 EventArgs 替换 System.Windows.RoutedEventArgs

于 2014-04-10T01:39:55.657 回答