0

在下面的代码中,试图获取单击的边框名称或作为文本块的孩子的文本我的问题是没有“eaclick.Handled = true;” 在代码中,它开始向我显示鼠标在单击之前输入的所有边框名称,而不仅仅是通过添加“eaclick.Handled = true;”单击的那个。向我展示了鼠标进入的所有第一个边框,在我看来,所有鼠标输入都保存在堆栈中,当单击 leftmousedown 时,它会获取堆栈,而不是让我获得我想要的最后一个鼠标输入,谁能解释我如何修复或我做错了什么?

for (int i = 0; i < NumPages; i++)
{

    Border borderaux = new Border();
    borderaux.Name = Convert.ToString(i);
    //borderaux.MouseEnter += borderaux_MouseEnter;
    Border clicked;
    borderaux.MouseEnter += (smouse, eamouse) =>
    {
        clicked = (Border)smouse;
        clicked.Cursor = Cursors.Hand;

        MouseLeftButtonDown += (sclick, eaclick) =>
        {
            if (eaclick.ClickCount == 1)
            {
                TextBlock opcao = (TextBlock)(clicked).Child;

                //string opcao="";
                MessageBox.Show("Pressed-->" + opcao.Text);
                //MessageBox.Show("Pressed-->" + clicked.Name);
                eaclick.Handled = true;
            }
        };
4

1 回答 1

0

问题是在产生问题的 MouseEnter 事件中使用 MouseLeftButtonDown 事件,当被点击时它会显示 x MessageBox 显示鼠标悬停到点击之前的所有边框数量,修复它会显示我的边框这实际上被点击了。

    for (int i = 0; i < NumPages; i++)
    {

        Border borderaux = new Border();
        borderaux.Name = Convert.ToString(i);
        //borderaux.MouseEnter += borderaux_MouseEnter;
        Border clicked;
        borderaux.MouseLeftButtonDown += (sclick, eaclick) =>
        {

            if (eaclick.ClickCount == 1)
            {
                TextBlock opcao = (TextBlock)((Border)sclick).Child;

                //string opcao="";
                MessageBox.Show("Pressed-->" + opcao.Text);
                //eaclick.Handled = true;
            }
        };

        borderaux.MouseEnter += (smouse, eamouse) =>
        {
            clicked = (Border)smouse;
            clicked.Cursor = Cursors.Hand;

        };
于 2014-04-16T10:33:05.780 回答