Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Custom Control, ItemsControl, MouseLeftButtonDown
13 replies. Latest Post by sladapter on April 11, 2009.
(0)
van_ice
Member
8 points
19 Posts
06-23-2008 11:25 AM |
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?
sladapter
All-Star
17441 points
3,172 Posts
06-23-2008 11:34 AM |
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"/>
<TextBlock Text="{Binding Caption}" Margin="4,0,0,0" />
</StackPanel>
</DataTemplate>
06-23-2008 11:41 AM |
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?
06-23-2008 12:06 PM |
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.
06-23-2008 12:10 PM |
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
06-23-2008 12:14 PM |
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
06-23-2008 12:17 PM |
I can't seem to download from that link?
06-23-2008 12:19 PM |
That page is slow, just wait a little longer the download link will show up at the bottom.
06-24-2008 1:31 PM |
sladapter,
Thank you very much, I worked thru you combobox and gained the knowledge that solved my problem!! Thank a million
IgnusLoD
4 points
2 Posts
09-17-2008 10:52 AM |
link broken
09-17-2008 11:00 AM |
Here is the new link:
09-17-2008 11:10 AM |
thz!!!
maxima120
88 points
85 Posts
04-09-2009 5:46 PM |
Can we have it one more time please!! :)
04-11-2009 6:09 PM |
Because now we have combobox in the SL2 product, I don't think you need my code anymore.