Skip to main content

Microsoft Silverlight

Unanswered Question ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2RSS Feed

(1)

Lluis
Lluis

Member

Member

18 points

7 Posts

ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Is this a bug?

 

Greetings

sgzwkrm
sgzwkrm

Member

Member

24 points

11 Posts

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...

eduardot
eduardot

Member

Member

6 points

3 Posts

Microsoft

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

sgzwkrm
sgzwkrm

Member

Member

24 points

11 Posts

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...

Lluis
Lluis

Member

Member

18 points

7 Posts

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

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

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

Lyynx
Lyynx

Member

Member

79 points

29 Posts

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)

 

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

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..

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

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.

snelldl
snelldl

Member

Member

148 points

141 Posts

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.

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

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...

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

sensenet_silverteam
sensenet...

Member

Member

2 points

1 Posts

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.

snelldl
snelldl

Member

Member

148 points

141 Posts

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
snelldl

Member

Member

148 points

141 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

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

saidhabanu
saidhabanu

Member

Member

2 points

1 Posts

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

Petunya
Petunya

Member

Member

42 points

35 Posts

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 ). 

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

Petunya
Petunya

Member

Member

42 points

35 Posts

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.
 

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

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

Petunya
Petunya

Member

Member

42 points

35 Posts

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.

Virrpanna
Virrpanna

Member

Member

26 points

11 Posts

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.

 

yaip
yaip

Member

Member

160 points

132 Posts

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>

Petunya
Petunya

Member

Member

42 points

35 Posts

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

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

 

 

    End Sub

yaip
yaip

Member

Member

160 points

132 Posts

Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

Petunya:

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

 

Since the HyperLinkButton is in ItemsControl, it is not available in the "handles" statement as you have shown.

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

<Website>
<Gadget>

Petunya
Petunya

Member

Member

42 points

35 Posts

Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

 Yaip,

Sorry, I am unfamiliar with VB.  However, you should be able to somehow use the hlbButton_Click method as the HyperlinkButton's event handler, correct?  I know you can do it in C# by simply saying in the XAML of the HyperlinkButton: Click="hlbButton_Click", no "Handles" statement necessary.  I wasn't sure how to translate to VB.

yaip
yaip

Member

Member

160 points

132 Posts

Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

I figured as much. I removed the "handles" statement. Still won't trap :(

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

<Website>
<Gadget>

Dimasina
Dimasina

Member

Member

2 points

1 Posts

Re: ListBoxItem don't trigger MouseLeftButtonDown in Beta 2

It is a bug.

After I got the same problem I tried to use MouseLeftButtonUp. Why not?

It works. Good.

Oops! It is not  good. It calls my method twice. Why? I believe that double call and bug in MouseLeftButtonDown are connected.

 

idragoev
idragoev

Member

Member

10 points

6 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Hi,

I faced same problem with left mouse button when styling ListBoxItems. See the Tip: Force firing MouseLeftButtonDown event on any place in a StackPanel. The trick I used is to add Background="Transparent" on the underlying control so now the left mouse button click is handled correctly.

 

yaip
yaip

Member

Member

160 points

132 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

 I tried that also. Doesn't work if the HyperlinkButton is in ItemsControl.

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

<Website>
<Gadget>

SilverlightShow
Silverli...

Participant

Participant

1133 points

193 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Hi,

I did a small example and it works just fine. Here the xaml and the source:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SilverlightTestApp.Page"
    Width="640" Height="480" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">

    <StackPanel>
        <ItemsControl x:Name="lbItems">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel x:Name="RootElement"  Background="Beige">
                        <TextBlock Text="{Binding Text}"/>
                        <HyperlinkButton FontSize="16" NavigateUri="{Binding Link}" Content="{Binding Link}" Click="HyperlinkButton_Click"/>
                </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>            
        </ItemsControl>
        
        <TextBlock x:Name="clickedItem" />
    </StackPanel>

</UserControl>
   1: using System;
   2: using System.Windows;
   3: using System.Windows.Controls;
   4: using System.Windows.Documents;
   5: using System.Windows.Ink;
   6: using System.Windows.Input;
   7: using System.Windows.Media;
   8: using System.Windows.Media.Animation;
   9: using System.Windows.Shapes;
  10: using System.Collections.Generic;
  11:  
  12: namespace SilverlightTestApp
  13: {
  14:     public partial class Page : UserControl
  15:     {
  16:         public Page()
  17:         {
  18:             // Required to initialize variables
  19:             InitializeComponent();
  20:  
  21:             this.lbItems.ItemsSource = new List<TestClass>(){
  22:             new TestClass(){Text="SilverlightShow.net", Link="http://www.silverlightshow.net"},
  23:             new TestClass(){Text="Silverlight.net", Link="http://www.silverlight.net"},
  24:             new TestClass(){Text="CompletIT.com", Link="http://www.completit.com"},
  25:             new TestClass(){Text="Google.com", Link="http://www.google.com"}};
  26:         }
  27:  
  28:           private void HyperlinkButton_Click( object sender, RoutedEventArgs e )
  29:         {
  30:             this.clickedItem.Text = ( ( HyperlinkButton )e.Source ).Content.ToString();
  31:         }
  32:     }
  33:  
  34:     public class TestClass
  35:     {
  36:         public string Text
  37:         {
  38:             get;
  39:             set;
  40:         }
  41:  
  42:         public string Link
  43:         {
  44:             get;
  45:             set;
  46:         }
  47:     }
  48: }
You can click on the HyperlinkButton and you will see the event is triggered as it should be.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
SilverlightShow Team,
www.SilverlightShow.net - news, articles, tips, examples, books

Rizwan Sharp
Rizwan S...

Member

Member

21 points

23 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I'm having the same issue where I need to handle MouseLeftButtonUp of ScrollBar control... Why would I need Scroll event only which will force me to query data repeatedly on short intervals?

I want to query database only when user moves the slider to the place of his/her choice and then release the mouse....

I hope to get a solution :(

 Best Regards,

RizwanSharp
C# MVP

Flyte
Flyte

Member

Member

14 points

8 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

sensenet_silverteam:

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.

 

 

Hi, I'd like to try and implement this workaround, but I can't figure out how to create instances of our own classes using the XAML. For example, with HTML and CSS, you'd tell the HTML element whichever CSS class you'd like it to be. This is not the case with XAML and C#. 

I am trying to use MouseLeftButtonDown and up on a slider, so I would like to create a class which implements the Slider class and override it's behavior like above. It's just like I say, I don't know how to create an instance of my custom class in XAML.

 

Could anybody please help?

 

Thanks :) 

yaip
yaip

Member

Member

160 points

132 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Try putting a HyperlinkButton within Items.Control and trap the MouseLeftButtonDown event. It won't work.

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

<Website>
<Gadget>

Flyte
Flyte

Member

Member

14 points

8 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Also, this method does not work for a Slider type..

 
Error    1    'BBOPreviewPlayer.MySlider.OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs)': no suitable method found to override   

Error    2    'BBOPreviewPlayer.MySlider.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)': no suitable method found to override    

Dave Britton
Dave Bri...

Member

Member

681 points

229 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I have fighting this same issue for a while now.  The best solution seems to be inheriting the slider and exposing your own events as needed. Something like this:

public class DragSlide : Slider

{

/// <summary>

/// Thrown when the thumb has been clicked, and dragging is initiated

/// </summary>

public event EventHandler<EventArgs> ThumbDragStarted;

/// <summary>

/// Thrown when the thumb has been released

/// </summary>

public event EventHandler<EventArgs> ThumbDragCompleted;public override void OnApplyTemplate()

{

base.OnApplyTemplate();

//Set up drag event handlers

Thumb thumb = this.GetTemplateChild("HorizontalThumb") as Thumb;if (thumb != null)

{

thumb.DragStarted += new DragStartedEventHandler(thumb_DragStarted);

thumb.DragCompleted += new DragCompletedEventHandler(thumb_DragCompleted);

}

}

void thumb_DragCompleted(object sender, DragCompletedEventArgs e)

{

OnThumbDragCompleted(
this, new EventArgs());

}

void thumb_DragStarted(object sender, DragStartedEventArgs e)

{

OnThumbDragStarted(
this, new EventArgs());

}

protected virtual void OnThumbDragStarted(object sender, EventArgs e)

{

if (ThumbDragStarted != null)

ThumbDragStarted(sender, e);

}

protected virtual void OnThumbDragCompleted(object sender, EventArgs e)

{

if (ThumbDragCompleted != null)

ThumbDragCompleted(sender, e);

}

}

Senior Engineer/Dev Manager, Vertigo Software
Vertigo

Flyte
Flyte

Member

Member

14 points

8 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Hi Dave, thanks for the response.

 

I would like to try your method, but I have not been able to find out how to create instances of my own classes in the XAML. I've searched for this and been unsuccessful in finding any answers. I have also asked in various forums and not been met with any success.

 

Is there a tutorial anywhere which shows how this is done, or if it's simple, would you be able to tell me?

 

Thanks again. 

Rizwan Sharp
Rizwan S...

Member

Member

21 points

23 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

"I would like to try your method, but I have not been able to find out how to create instances of my own classes in the XAML."

Simply Open control browse dialog in expression blend, go to custom controls tab and select your control from the list. Now your control should be added to tool box in expression blend.

Double click the control and it will be added on your UI.

 I hope this helps,

Best Regards,

 

RizwanSharp
C# MVP

SilverlightShow
Silverli...

Participant

Participant

1133 points

193 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Flyte:

I would like to try your method, but I have not been able to find out how to create instances of my own classes in the XAML. I've searched for this and been unsuccessful in finding any answers. I have also asked in various forums and not been met with any success.

Is there a tutorial anywhere which shows how this is done, or if it's simple, would you be able to tell me?

Hi, Flyte! Take a look at this article about how to create a custom control - http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Control-The-Basics.aspx - and if you still have questions don't hesitate to ask!

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
SilverlightShow Team,
www.SilverlightShow.net - news, articles, tips, examples, books

Flyte
Flyte

Member

Member

14 points

8 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Ah, excellent - thank you both for that! Big Smile

 

Dave Britton
Dave Bri...

Member

Member

681 points

229 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Let me know how it works out.

I have been 100% in the 1.0 SL word up until now, so this is all new stuff to me too.  Cool stuff though.

Senior Engineer/Dev Manager, Vertigo Software
Vertigo

weitzhandler
weitzhan...

Member

Member

23 points

18 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

I thought WPF is better!

These Microsoft twists are disgusting!!!

 

Why do they matther if there will be as many handler as possible!!!!

It doesn't cost any performance, I they're just Gothamites

 

this pisses me off

 

Shimmy

rdlecler
rdlecler

Member

Member

4 points

2 Posts

Re: ListBoxItem don´t trigger MouseLeftButtonDown in Beta 2

Mouse events in ScrollBar were not being triggered for me either. However, if you hook up the Scroll event the ScrollEventArgs has a enumberation data member called ScrollEventType which comes from System.Windows.Controls.Primitives. If you mouseclick on the scrollbar nothing happens. If you move you get "ThumbTrack" and whenever you lift your mouse you get "EndScroll". So if you just click UpDown, you will just get an EndScroll event. You may be able to use the scroll bar this way to control other controls. Best RDL

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities