Search code examples
silverlightstackmouseentermouseleftbuttondown

MouseEnter Stack


In the code that follows,was trying get the border that was clicked the name or the text of the child that's a textblock my problem is that without "eaclick.Handled = true;" in the code it starts showing me all the Names of the border that the mouse has entered before the click and not not only the oned that was clicked by adding "eaclick.Handled = true;" shows me alls the first border that the mouse has entered,it seems to me that's saving in a stack all the mouseenters and when Click in leftmousedown it goes get that stack instand of getting me the last mouseenter that I want can anyone explain me how to fix or what I am doing wrong?

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;
            }
        };

Solution

  • the problem was that using the MouseLeftButtonDown event inside MouseEnter event that was giving the problem,that when was clicked it would show me x MessageBox showing all the number of borders that the mouse had hovered until the click,with the fix it show me the border that was actualy clicked.

        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;
    
            };