メニューの一部を作成して、ユーザーがメニューを再編成できるようにしています。このメニューには、12個の要素を持つgrid(4x3)があり、そのすべてが、Buttonを拡張するために作成したクラスであるNavButtonタイプです。NavButtonには、ボタンをグリッド全体で移動できるドラッグ機能があり、現在、各ボタンをMouseEnterイベントのどこに配置するかを決定しています。
NavButtonを再配置する場所を決定するために、MouseEnterで明るくなる細い長方形を配置したので、それがどのように機能するかを考えました。私の問題は、NavButtonが長方形の上にドラッグされると、マウスが長方形の上にあるNavButtonの上にあるため、MouseEnterイベントが発生しないことです。紛らわしいと思われる場合は申し訳ありませんが、以下にコードを投稿します。
そうは言っても、MouseEnterイベントの動作と同様に、NavButtonがRectangleに「入る」タイミングを決定するイベントを作成できるかどうか疑問に思っています。
C#:
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;
}
XAML:
//The Style is in my ResourceDictionary
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="Black" />
<Setter Property="Height" Value="151" />
<Setter Property="Width" Value="10" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Opacity" Value=".6" />
<EventSetter Event="MouseEnter" Handler="rectangle_MouseEnter" />
<EventSetter Event="MouseLeave" Handler="rectangle_MouseLeave" />
</Style>
...
<Grid Name="grid" Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="22"></RowDefinition>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0" Name="rect00" />
<Rectangle Grid.Row="0" Grid.Column="1" Name="rect01" />
<Rectangle Grid.Row="0" Grid.Column="2" Name="rect02" />
<Rectangle Grid.Row="1" Grid.Column="0" Name="rect10" />
<Rectangle Grid.Row="1" Grid.Column="1" Name="rect11" />
<Rectangle Grid.Row="1" Grid.Column="2" Name="rect12" />
<Rectangle Grid.Row="2" Grid.Column="0" Name="rect20" />
<Rectangle Grid.Row="2" Grid.Column="1" Name="rect21" />
<Rectangle Grid.Row="2" Grid.Column="2" Name="rect22" />
<Rectangle Grid.Row="3" Grid.Column="0" Name="rect30" />
<Rectangle Grid.Row="3" Grid.Column="1" Name="rect31" />
<Rectangle Grid.Row="3" Grid.Column="2" Name="rect32" />
<TextBlock Grid.Row="5" Grid.Column="3" Name="TB" />
</Grid>
私はWPFにかなり慣れていないので、洞察をいただければ幸いです。ありがとうございました。