title: WPF Creating Custom Events
body: <p>I am working on a part of a menu to allow it to be re-organized by its user. This menu has a grid(4x3) with 12 elements, all of which are of the type NavButton, a class I created that extends Button. In the NavButton I have a drag feature that allows the buttons to be moved throughout the grid and currently I am working on determining where each button should land on the MouseEnter event.</p>
  
  <p>In order to determine where the NavButtons should be re-positioned, I have placed thin rectangles that will brighten on MouseEnter, or so I thought that is how they should work. My issue is that as the NavButton is dragged over the rectangles the MouseEnter event will not fire as the Mouse is over the NavButton which is over the Rectangle. Sorry if that sounds confusing, but I will post code below.</p>
  
  <p>All of that said, I am wondering if it is possible at all to create an event to determine when the NavButton "Enters" the Rectangle, similar to how the MouseEnter event works?</p>
  
  <p><strong>C#:</strong></p>
  
  <pre><code>    private void rectangle_MouseEnter(object sender, MouseEventArgs e)
      {
          foreach (UIElement uie in this.grids[tabNavigation.SelectedIndex].Children)
          {
              if (uie.GetType() == typeof(NavButton_UC))
              {
                  if ((uie as NavButton_UC).IsDragging)
                  {
                      (sender as Rectangle).Fill = Brushes.Gray;
                  }
              }
          }
      }
  
      private void rectangle_MouseLeave(object sender, MouseEventArgs e)
      {
          (sender as Rectangle).Fill = Brushes.Black;
      }
  </code></pre>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>             //The Style is in my ResourceDictionary
               &lt;Style TargetType="Rectangle"&gt;
                  &lt;Setter Property="Fill" Value="Black" /&gt;
                  &lt;Setter Property="Height" Value="151" /&gt;
                  &lt;Setter Property="Width" Value="10" /&gt;
                  &lt;Setter Property="HorizontalAlignment" Value="Left" /&gt;
                  &lt;Setter Property="Opacity" Value=".6" /&gt;
                  &lt;EventSetter Event="MouseEnter" Handler="rectangle_MouseEnter" /&gt;
                  &lt;EventSetter Event="MouseLeave" Handler="rectangle_MouseLeave" /&gt;
              &lt;/Style&gt;
              ...
              &lt;Grid Name="grid" Background="Black"&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                      &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                      &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition Height="22"&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;Rectangle Grid.Row="0" Grid.Column="0" Name="rect00" /&gt;
                  &lt;Rectangle Grid.Row="0" Grid.Column="1" Name="rect01" /&gt;
                  &lt;Rectangle Grid.Row="0" Grid.Column="2" Name="rect02" /&gt;
                  &lt;Rectangle Grid.Row="1" Grid.Column="0" Name="rect10" /&gt;
                  &lt;Rectangle Grid.Row="1" Grid.Column="1" Name="rect11" /&gt;
                  &lt;Rectangle Grid.Row="1" Grid.Column="2" Name="rect12" /&gt;
                  &lt;Rectangle Grid.Row="2" Grid.Column="0" Name="rect20" /&gt;
                  &lt;Rectangle Grid.Row="2" Grid.Column="1" Name="rect21" /&gt;
                  &lt;Rectangle Grid.Row="2" Grid.Column="2" Name="rect22" /&gt;
                  &lt;Rectangle Grid.Row="3" Grid.Column="0" Name="rect30" /&gt;
                  &lt;Rectangle Grid.Row="3" Grid.Column="1" Name="rect31" /&gt;
                  &lt;Rectangle Grid.Row="3" Grid.Column="2" Name="rect32" /&gt;
                  &lt;TextBlock Grid.Row="5" Grid.Column="3" Name="TB" /&gt;
              &lt;/Grid&gt;
  </code></pre>
  
  <p>I am fairly new to WPF, so any insight would be appreciated. Thank you.</p>