code_junkie

How do I set the ZIndex of a Listbox Item on MouseEnter

Nov 14th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. private void ListItem_MouseEnter(object sender, MouseEventArgs e)
  2. {
  3. var grid = sender as Grid;
  4. grid.SetValue(Canvas.ZIndexProperty, 5);
  5. }
  6.  
  7. <UserControl x:Class="SilverlightApplication1.Page"
  8. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  9. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  10. Width="400" Height="300">
  11. <Grid x:Name="LayoutRoot" Background="White">
  12. <ListBox x:Name="ListBox1">
  13. <ListBoxItem Content="Test 1" MouseEnter="ListBoxItem_MouseEnter" />
  14. <ListBoxItem Content="Test 2" MouseEnter="ListBoxItem_MouseEnter" />
  15. <ListBoxItem Content="Test 3" MouseEnter="ListBoxItem_MouseEnter" />
  16. <ListBoxItem Content="Test 4" MouseEnter="ListBoxItem_MouseEnter" />
  17. </ListBox>
  18. </Grid>
  19. </UserControl>
  20.  
  21. using System;
  22. using System.Windows.Controls;
  23. using System.Windows.Input;
  24.  
  25. namespace SilverlightApplication1
  26. {
  27. public partial class Page : UserControl
  28. {
  29. public Page()
  30. {
  31. InitializeComponent();
  32. }
  33.  
  34. private void ListBoxItem_MouseEnter(object sender, MouseEventArgs e)
  35. {
  36. ListBoxItem listBoxItem = (ListBoxItem)sender;
  37.  
  38. listBoxItem.SetValue(Canvas.ZIndexProperty, 5);
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment