Page view counter
ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2
Last post 07-08-2008 10:35 AM by Dave Britton. 43 replies.
Sort Posts:
06-07-2008 6:23 AM
ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Is this a bug?

 

Greetings

Lluis

Loading...
Joined on 04-16-2008
Posts 7
06-07-2008 11:16 AM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2
And I have found another bug is...Button don't trigger MouseLeftButtonDown\Up in Beta2...faint...
sgzwkrm

Loading...
Joined on 03-10-2008
Posts 11
06-07-2008 9:11 PM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

The event is not getting fire because Button class is marking the event as Handle but you should be able to use Click event.

Thanks

Eduardo

eduardot

Loading...
Joined on 05-05-2007
Redmond
Posts 3
06-07-2008 10:33 PM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

OK, I have read this following in the help document:

Certain control classes (for example Button) provide control-specific handling for mouse events such as MouseLeftButtonDown. The control-specific handling typically involves handling the event at a class level rather than at the instance level, and marking the MouseLeftButtonDown event data's Handled value as true such that the event cannot be handled by instances of the control class, nor by other elements (at a class or instance level) anywhere further along the event route. In the case of Button, the class design does this so that the event Click can be raised instead.

 

But I think Click can't substitute Down\Up...

sgzwkrm

Loading...
Joined on 03-10-2008
Posts 11
06-09-2008 8:22 AM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

 

I understand this behaviour in button, but not in ListboxItem. Also breaks compatibility with WPF

 

Greetings

Lluis

Loading...
Joined on 04-16-2008
Posts 7
06-09-2008 5:02 PM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Now in beta 2 MouseLeftButtonDown/MouseLeftButtonUp events no longer fire for Button/ListboxItem etc. How do we do Drag/Drop with those controls if we can not catch the MouseDown/Up event?

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-09-2008 5:49 PM
Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I'd like to add that this also seems to be a problem when clicking a cell in the DataGrid. I can no longer respond to a cell being clicked!Indifferent

CleverCoder

Loading...
Joined on 05-16-2008
Raleigh, NC, US
Posts 152
06-10-2008 4:39 AM
Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I've discovered the same problem with the slider control. It no longer raises MouseLeftButtonDown, MouseLeftButton up or quite possibly any of the Mouse events.

I can raise ValueChanged no problems. 

Also I tried a MouseLeftButtonDown on the container grid thinking maybe it was catching it and found that I could *sometimes* get it to be raised depending where I clicked. Most of the time it did not... (could have been only raising if I was exactly over the gridlines or something weird? dunno)

 

Lyynx

Loading...
Joined on 04-26-2008
Perth, Australia
Posts 12
06-10-2008 10:45 AM
Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I'm not religous, but dear god. I hope they fix these quirks and release another beta SOON! This is NOT good. I'm having so much headache with the DataGrid, it's starting to worry me. Isn't the goal to fix more bugs, and not introduce new ones? yikes.

Maybe if the control that "Handled" the event was smart enough to see "Gee,.. I have the same event that people might subscribe to.." and NOT digest the thing.. because the Grid has a MouseButton Down, I would expect to ALWAYS get the event as a consumer of the grid..

CleverCoder

Loading...
Joined on 05-16-2008
Raleigh, NC, US
Posts 152
06-10-2008 11:01 AM
Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I have the same feeling. I think they rushed. Not only they did not fix a lot old problems, they break even more. The old problems I can still live with if they did not break my work-around. But  now some those work-around are also broken.

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-10-2008 3:27 PM
Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Well, for the record, I am now at the point where I'm trying to fix an issue with a listbox. Guess what it involves. MouseLeftButtonDown!  In my case, it's a list box inside of a popup, that when clicked, will close the popup.  It seems that SelectionChanged works.. but with one item, the selection will never change... And of course, MouseLeftButtonDown does not do a darn thing.

Crossing fingers that they can fix this SOON.

CleverCoder

Loading...
Joined on 05-16-2008
Raleigh, NC, US
Posts 152
06-10-2008 3:34 PM
Re: Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I've did the same thing with selectionchanged, but when I try to close the popup, I get an error and my form goes blank.

snelldl

Loading...
Joined on 08-15-2006
Hillsdale, MI
Posts 77
06-10-2008 4:03 PM
Re: Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Are you still getting error when try to close the popup in SelectionChanged event? I was hoping they fixed that one. I haven't tried it yet. I have a workaround in beta 1 for this problem and hoping I don't have to use that anymore after beta 2. 

 That's what I mean they did not fix many old problems we reported, but just break more.
 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-10-2008 4:38 PM
Re: Re: Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

 Funny.. I tried the same thing, with the same result. (CLosing a popup when an item in the list is selected) BOOM! Crash!  

I found a workaround was to create a DispatcherTimer (50 ms) and close the popup from there. So far, that has worked.  NOw I'm trying to battle some other quirk involving a missing watermarked text box... grrrr...

CleverCoder

Loading...
Joined on 05-16-2008
Raleigh, NC, US
Posts 152
06-10-2008 4:42 PM
Re: Re: Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

 Yes, use timer is the work-around. So we have to keep that.

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-11-2008 9:13 AM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Nope, it's not a bug, it's just a new way of handling pointing devices, because I guess mouse is not the primary input device in Silverlight anymore. Since then the controls became Click event orientated.

Here's a quick&dirty workaround (without indepth analysis of the unseen side effects!), but it provides an easy solution for those who want to use the MouseDown/Up events in the old fashioned way.

public class MyButton : Button
{

 
public MyButton()
  {
   
this.MouseLeftButtonDown += new MouseButtonEventHandler(MyButton_MouseLeftButtonDown);
   
this.MouseLeftButtonUp += new MouseButtonEventHandler(MyButton_MouseLeftButtonUp);
  }

  void MyButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
   
this.Content = "mouse down";
  }

  void MyButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  {
   
this.Content = "mouse up";
  }

  protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
  {
   
base.OnMouseLeftButtonDown(e);
    e.Handled =
false;
  }

  protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
  {
   
base.OnMouseLeftButtonUp(e);
    e.Handled =
false;
  }
}

Hope it helps.

sensenet_silverteam

Loading...
Joined on 06-11-2008
Posts 1
06-11-2008 9:32 AM
Re: Re: Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Man, it sounds like were building similar apps!

What's the code to create that timer and where do you place it?

snelldl

Loading...
Joined on 08-15-2006
Hillsdale, MI
Posts 77
06-11-2008 9:46 AM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Nevermind. I figured it out from an example in the SL chm.

snelldl

Loading...
Joined on 08-15-2006
Hillsdale, MI
Posts 77
06-11-2008 9:50 AM
Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

 

...... 

public class MyButton : Button
{

 
public MyButton()
  {
   
this.MouseLeftButtonDown += new MouseButtonEventHandler(MyButton_MouseLeftButtonDown);
   
this.MouseLeftButtonUp += new MouseButtonEventHandler(MyButton_MouseLeftButtonUp);
  }

  void MyButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
   
this.Content = "mouse down";
  }

...... 

 

Even this approach didnt work as expected

saidhabanu

Loading...
Joined on 06-11-2008
Posts 1
06-11-2008 5:00 PM
Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

CleverCoder:

Well, for the record, I am now at the point where I'm trying to fix an issue with a listbox. Guess what it involves. MouseLeftButtonDown!  In my case, it's a list box inside of a popup, that when clicked, will close the popup.  .....

 

I am having a similar, strange issue.  I'm not sure if this is the thread to post it, since it is slightly different.  For Beta 1 I followed Shawn Burke's tutorial for creating an "ExpandoHeaderControl" and then templated it so it ended up looking more like a typical drop-down control.  The problem I ran into was that the drop-down content was being hidden behind a datagrid, instead of showing on top.  I tried several ways of getting it to be on top - tried setting canvas.zindex, tried adding it as the last control, etc.  I was hoping that something magical would happen in Beta 2 and one of those methods would fix the problem.  I was wrong.

So, I saw somebody suggest using a Popup.  I converted to that today, though I did not like having to set the vertical offset directly in my template... I tried doing so using template binding, to make my control more re-usable, but it did not work.

To get to the point, I have a listbox inside of a popup now, and the SelectionChanged event is only firing the first time an item is selected.  Meaning, if I select itemA, then select itemB, everything is working fine, until I try to select itemA again - nothing happens.

I don't know if it's any help, but I am successfully closing the popup in my selection changed event handler (for the times that it actually fires ). 

Petunya

Loading...
Joined on 06-06-2008
Sacramento, Ca
Posts 35
06-11-2008 5:44 PM
Re: Re: Re: Re: Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

SelectionChanged event only fires (as the event name indicated) when selection changed. If you click on the item that is already selected, this event won't fire because the selection did not change. That is the same behavior since beta1.

If you do not want that behavior,  in beta 1 you can catch ListBox.MouseDown event. In beta 2 they took that event away. But Grid still can fire MouseDown event, so if you wrap your List Item in a Grid and hookup MouseDown event on the Grid you can still catch it.

Here is how you do it: 

  <ListBox x:Name="List" >
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Background="Transparent" MouseLeftButtonDown="Item_MouseLeftButtonDown" Cursor="Hand" Loaded="Item_Loaded">
                                    <TextBlock x:Name="Text" Margin="5, 5, 5, 5" Text="{Binding Text}" FontSize="12"  />                                  
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
</ListBox>

 

        private void Item_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement g = sender as FrameworkElement;
            g.Width = Menu.ActualWidth;  // this will make the Grid stretch to the whole width of the ListBox
        }

        private void Item_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
             //Do things you want to do here when you click a your list item
        }

 
 

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-11-2008 7:26 PM
Re: Re: Re: Re: Re: ListBoxItem don&amp;amp;amp;#180;t trigger MouseLeftButtonDown in Beta 2

 Thank you for your response, I think I might be able to come up with a work around based on this. 

However, I want to point out that the problem is that the selection changed event is not firing when it is supposed to.  I am not trying to have it fire when clicking on the selected item.  If I select A, then select B, B is the current selection, and clicking A should fire the selection changed event, but it does not.

It's not firing for items that were previously selected, even if they are not currently selected.  Just re-reading this it sounds confusing, but the basic functionality of a listbox firing the selection changed event when an item other than the selected item is clicked, is not working under a certain circumstance.  It's almost like the listbox is "remembering" all the selections I have made and only firing selection changed if I click something new.
 

Petunya

Loading...
Joined on 06-06-2008
Sacramento, Ca
Posts 35
06-11-2008 9:10 PM
Re: Re: Re: Re: Re: ListBoxItem don&amp;amp;amp;#180;t trigger MouseLeftButtonDown in Beta 2

Sorry I did not read you post carefully.

But I just tested my Listbox, it does not have the problem you are having. My listbox is like the one I just posted. But I use SelectionChanged event, not the mousedown event.  If you could post your Xaml I'll see if I can reproduce the problem.

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 2,689
06-12-2008 10:55 AM
Re: Re: Re: Re: Re: ListBoxItem don&amp;amp;amp;#180;t trigger MouseLeftButtonDown in Beta 2

 No need to be sorry, I am having a hard time explaining in a way that isn't confusing (for me, at least).  I am going to try using the mouse down event and see if I can get around my problem.

I posted snippets of code and the full xaml for the listbox here if you would like to view it.  I am wondering if the issue has something to do with the listbox being inside of a popup, or the popup being closed before the selection changed event handler has finished its business, etc.  The listbox behaves normally under normal conditions, and though I wasn't noticing the issue before, I didn't notice it until after I put my drop-down content inside a popup.

Petunya

Loading...
Joined on 06-06-2008
Sacramento, Ca
Posts 35
06-17-2008 1:47 AM
ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

This is really confusing!

Listbox doesn’t trigger MouseLeftButtonDown anymore, but still triggers MouseLeftButtonUp.
In some situations they are of course interchangeable.

I really would like to know hove the silverlight team developers have reasoned, since it would give me a clue hove to think and design the apps for the future release.

 

Virrpanna

Loading...
Joined on 06-21-2007
Posts 7
06-17-2008 9:59 PM
Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

 I am faced with the same problem but not with a ListBox but a HyperLinkButton in an ItemsControl. I have following xaml:

 

            <ItemsControl x:Name="itmStudents"  Margin="0,0,0,0" Canvas.Top="63.287" Canvas.Left="172.2" Padding="10"   >

                  <ItemsControl.ItemTemplate>

                        <DataTemplate>

                                    <HyperlinkButton x:Name="hlbButton" FontSize="16"   ></HyperlinkButton>

                        </DataTemplate>

                  </ItemsControl.ItemTemplate>

            </ItemsControl>

 

 

and following in my code-behind:

 

    Private Sub itmStudents_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles itmStudents.MouseLeftButtonDown

        btnSubmit.Opacity = 0

        txtStudent.Opacity = 0

        lblStudent.Opacity = 0

        Me.itmStudents.Opacity = 0

        txtMessage.Text = "Please wait..."

        Dim textB As TextBlock = e.Source

        Dim linkB As HyperlinkButton = textB.DataContext

        Dim s As String = linkB.Tag

 

        Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient

        AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted

        asmx2.GetStudentArtAsync(Convert.ToInt32(linkB.Tag))

 

 

    End Sub

But this won't work. 

 

Thanks
I love computers because: MY WISH IS THEIR COMMAND :)

<Website>

<Gadget>

yaip

Loading...
Joined on 10-27-2003
Los Angeles, CA
Posts 94
06-18-2008 11:04 AM
Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

Yaip,

 I think you may be able to work around this problem.  Instead of relying on the item's mouse down event, hook into the HyperlinkButton's click event.  In that case your method should only change slightly, with "sender" being the HyperlinkButton.  Below I have put the XAML and VB, though I don't know VB too well so please forgive any mistakes.
 

<ItemsControl x:Name="itmStudents"  Margin="0,0,0,0" Canvas.Top="63.287" Canvas.Left="172.2" Padding="10"   >

                  <ItemsControl.ItemTemplate>

                        <DataTemplate>

                                    <HyperlinkButton x:Name="hlbButton" FontSize="16" Click="hlbButton_Click"  ></HyperlinkButton>

                        </DataTemplate>

                  </ItemsControl.ItemTemplate>

            </ItemsControl>

 Private Sub hlbButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles hlbButton.Click

        btnSubmit.Opacity = 0

        txtStudent.Opacity = 0

        lblStudent.Opacity = 0

        Me.itmStudents.Opacity = 0

        txtMessage.Text = "Please wait..."

        Dim linkB As HyperlinkButton = sender

        Dim s As String = linkB.Tag

 

        Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient

        AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted