Skip to main content

Microsoft Silverlight

Answered Question Custom Control, ItemsControl, MouseLeftButtonDownRSS Feed

(0)

van_ice
van_ice

Member

Member

8 points

19 Posts

Custom Control, ItemsControl, MouseLeftButtonDown

I have a custom control that contains an ItemsControl defined in generic.xaml, I'm trying find out which Item in the Items control has been clicke on with the left button of the mouse. How would I go about getting that information?

 

 

<ItemsControl x:Name="CommandsListBox" Grid.Row="1" Margin="1">

<ItemsControl.ItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<Border Background="#FFE5E5E5">

<Image Source="{Binding Glyph}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</Border>

<TextBlock Text="{Binding Caption}" Margin="4,0,0,0" />

</StackPanel>

</DataTemplate>

</ItemsControl.ItemTemplate>

</ItemsControl>

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Custom Control, ItemsControl, MouseLeftButtonDown

Hook up  MouseLeftButtonDown event to the StackPanel, so you know which item is clicked.

 <ItemsControl x:Name="CommandsListBox" Grid.Row="1" Margin="1">

<ItemsControl.ItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal" MouseLeftButtonDown="Item_MouseLeftButtonDown">

<Border Background="#FFE5E5E5">

<Image Source="{Binding Glyph}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</Border>

<TextBlock Text="{Binding Caption}" Margin="4,0,0,0" />

</StackPanel>

</DataTemplate>

</ItemsControl.ItemTemplate> </ItemsControl>

sladapter
Software Engineer
Aprimo, Inc

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

van_ice
van_ice

Member

Member

8 points

19 Posts

Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

When I add that code to the ItemsControl in generic.xaml and the corresponding event handler in the custom controls code behind I get an error Sys.InvalidOperationException that leads to XamlParseException.

 

Any other ideas?

 

 

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

I don't know what you are trying to do.  Are you writing a custom control that have a ItemsControl inside that custom control? Or you just want to use ItemsControl in your UserControl?

Sorry, I read your first post again, you are writing a custom control that contains a ItemsControl. I don't think you can hook up event in Template XAML in generic.Xaml, You have to do it in code in OnApplyTemplate function.

 

 

 

 

 

 

 

 

sladapter
Software Engineer
Aprimo, Inc

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

van_ice
van_ice

Member

Member

8 points

19 Posts

Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

Yeah, its a custom control. I'm trying to to use an ItemsControl in a Popup control to get around the issues of using the ListBox control in the popup (i've seen your posts around those issues and ran into the same problems in SL Beta 2).  I thought the ItemsControl may provide a less buggy way to accomplish the goal.

 The goal is just a list of things the user can select in the popup and then the control fires an event and then makes the popup go away.

 

P.S thanks for helping me on this one

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

Are you writing a combobox control? If yes, take a look at this one I wrote:

http://www.2shared.com/file/3743583/b72b0575/SilverlightComboBox.html

sladapter
Software Engineer
Aprimo, Inc

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

van_ice
van_ice

Member

Member

8 points

19 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

I can't seem to download from that link?

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Answered Question

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

That page is slow, just wait a little longer the download link will show up at the bottom.

sladapter
Software Engineer
Aprimo, Inc

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

van_ice
van_ice

Member

Member

8 points

19 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

sladapter, 

Thank you very much, I worked thru you combobox and gained the knowledge that solved my problem!! Thank a million

IgnusLoD
IgnusLoD

Member

Member

4 points

2 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

link broken Sad

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

Here is the new link:

 http://www.2shared.com/file/3743583/b72b0575/SilverlightComboBox.html

sladapter
Software Engineer
Aprimo, Inc

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

IgnusLoD
IgnusLoD

Member

Member

4 points

2 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

 thz!!!Big Smile

maxima120
maxima120

Member

Member

88 points

85 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

Can we have it one more time please!! :)

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Re: Re: Re: Custom Control, ItemsControl, MouseLeftButtonDown

Because now we have combobox in the SL2 product, I don't think you need my code anymore. 

sladapter
Software Engineer
Aprimo, Inc

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities