Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ITypeOfObjectsBoundToListBox DetermineHoveredItem()
- {
- Point screenPosition = ListBox.MousePosition;
- Point listBoxClientAreaPosition = listBox.PointToClient(screenPosition);
- int hoveredIndex = listBox.IndexFromPoint(listBoxClientAreaPosition);
- if (hoveredIndex != -1)
- return listBox.Items[hoveredIndex] as ITypeOfObjectsBoundToListBox;
- else
- return null;
- }
- public static class MouseInput
- {
- // TME_HOVER
- // The caller wants hover notification. Notification is delivered as a
- // WM_MOUSEHOVER message. If the caller requests hover tracking while
- // hover tracking is already active, the hover timer will be reset.
- private const int TME_HOVER = 0x1;
- private struct TRACKMOUSEEVENT
- {
- // Size of the structure - calculated in the constructor
- public int cbSize;
- // value that we'll set to specify we want to start over Mouse Hover and get
- // notification when the hover has happened
- public int dwFlags;
- // Handle to what's interested in the event
- public IntPtr hwndTrack;
- // How long it takes for a hover to occur
- public int dwHoverTime;
- // Setting things up specifically for a simple reset
- public TRACKMOUSEEVENT(IntPtr hWnd)
- {
- this.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
- this.hwndTrack = hWnd;
- this.dwHoverTime = SystemInformation.MouseHoverTime;
- this.dwFlags = TME_HOVER;
- }
- }
- // Declaration of the Win32API function
- [DllImport("user32")]
- private static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
- public static void ResetMouseHover(IntPtr windowTrackingMouseHandle)
- {
- // Set up the parameter collection for the API call so that the appropriate
- // control fires the event
- TRACKMOUSEEVENT parameterBag = new TRACKMOUSEEVENT(windowTrackingMouseHandle);
- // The actual API call
- TrackMouseEvent(ref parameterBag);
- }
- <ListBox Width="400" Margin="10" ItemsSource="{Binding Source={StaticResource myTodoList}}">
- <ListBox.ItemTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Path=TaskName}" ToolTipService.ToolTip="{Binding Path=TaskName}"/>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- int hoveredIndex = -1;
- private void lstCars_MouseMove(object sender, MouseEventArgs e)
- {
- int newHoveredIndex = lstCars.IndexFromPoint(e.Location);
- if (hoveredIndex != newHoveredIndex)
- {
- hoveredIndex = newHoveredIndex;
- if (hoveredIndex > -1)
- {
- tt1.Active = false;
- tt1.SetToolTip(lstCars, ((Car)lstCars.Items[hoveredIndex]).InsuranceGroup);
- tt1.Active = true;
- }
- }
- }
- <Style x:Key="radioListBox" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
- <Setter Property="BorderThickness" Value="0" />
- <Setter Property="Margin" Value="5" />
- <Setter Property="Background" Value="{x:Null}" />
- <Setter Property="ItemContainerStyle">
- <Setter.Value>
- <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ListBoxItem">
- <Grid Background="Transparent">
- <RadioButton Focusable="False" IsHitTestVisible="False" IsChecked="{TemplateBinding IsSelected}" Content="{Binding MyName}"/>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- <Setter Property="ToolTip" Value="{Binding MyToolTip}" />
- </Style>
- </Setter.Value>
- </Setter>
- </Style>
Add Comment
Please, Sign In to add comment