XamlParerException:尝试将文本链接到Xaml页面时

XamlParerException:尝试将文本链接到Xaml页面时,xaml,windows-phone-8,Xaml,Windows Phone 8,(Windows Phone项目)我正在尝试创建一个场景,假设用户单击文本并显示xaml页面。 该文本称为“条款和条件” Xaml接口代码 <TextBlock TextWrapping="Wrap" Height="30" Foreground="Red" MouseEnter="MouseEnter_Agent"> <Underline> <Run Text="Read

(Windows Phone项目)我正在尝试创建一个场景,假设用户单击文本并显示xaml页面。 该文本称为“条款和条件”

Xaml接口代码

 <TextBlock TextWrapping="Wrap" Height="30" Foreground="Red"  MouseEnter="MouseEnter_Agent">
                    <Underline>
                        <Run Text="Read JizAgent Terms and Conditions"/>
                    </Underline>
                    <LineBreak/>
                    <Run/>
                </TextBlock>


当我单击文本-XamlParerException时,我得到了一个错误,您在事件处理程序的签名中使用了错误的
EventArgs
类。您应该使用
MouseEventArgs
。就拿这个基本的例子来说:

<Window x:Class="MouseEventArgs.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MouseEventArgs" Height="300" Width="300">

    <Grid x:Name="LayoutRoot"
          Background="Green"
          MouseEnter="Grid_MouseEnter" />
</Window>

代码隐藏:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace MouseEventArgs
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        void Grid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            LayoutRoot.Background = new SolidColorBrush(Colors.Red);
        }
    }
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
名称空间MouseEventArgs
{
/// 
///Window1.xaml的交互逻辑
/// 
公共部分类Window1:Window
{
公共窗口1()
{
初始化组件();
}
void Grid_MouseEnter(对象发送器,System.Windows.Input.MouseEventArgs e)
{
LayoutRoot.Background=新的SolidColorBrush(Colors.Red);
}
}
如果失败,则必须是
agenterms.xaml
中的标记有问题

void MouseEnter_Agent(object sender, System.Windows.Input.KeyEventArgs e)
处理程序的签名错误。请将其替换为:

void MouseEnter_Agent(object sender, System.Windows.Input.MouseEventArgs e)

TextBlock
可以包含多个
Inline
s。您的标记甚至不会编译为
TextBlock
不能包含
StackPanel
。(为了让阅读者了解这一点,我最初建议在
TextBlock
Content
属性中有多个对象可能会导致异常,但没有意识到它接受多个
内联
控件)!这应该是针对windows Phone的!抱歉,我忘了添加这是一个windows Phone项目。在这种情况下,我仍然会尝试更新您的事件处理程序以使用
MouseEventArgs
类,查看您是否遇到相同的异常。如果我使用了错误的方法签名,我的WPF项目实际上不会编译,但我不确定是否不会Windows Phone编译器的行为方式与此相同。您正在使用哪个XAML实现(例如WPF、WinRT XAML)?它适用于Windows Phone。
void MouseEnter_Agent(object sender, System.Windows.Input.MouseEventArgs e)