2
我重寫模板進行分組框標題是這樣的:鼠標事件被後面的元素搞亂了嗎?
<Style x:Key="styleScoreComp" TargetType="{x:Type GroupBox}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding}" Foreground="Black" FontWeight="Bold" FontSize="20" VerticalAlignment="Center"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" >
<Composer:AddElementButton Type="Composite"/>
<Composer:AddElementButton Type="Calculation"/>
<Composer:AddElementButton Type="SimulationValue"/>
</StackPanel>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
AddElementButton
<Border x:Name="borderButton" BorderThickness="1" BorderBrush="Silver" CornerRadius="4" Cursor="Hand" Margin="5" Background="White" Width="50" Height="45" MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="borderButton_MouseLeftButtonUp">
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image x:Name="imgType" Source="{Binding TypeImage, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
Cursor="Hand" Stretch="Uniform" Width="24" Height="24" Canvas.Top="3" Canvas.Left="13" />
<Image Canvas.Top="30" Canvas.Left="7" Source="add.png" Cursor="Hand" Stretch="Uniform" Width="36" Height="9" VerticalAlignment="Bottom" />
</Canvas>
</Border>
基本上,它的工作原理,但是當你的鼠標在按鍵的中間,它認爲該鼠標有離開邊境管制。當鼠標移動到GroupBox邊框的位置時,看起來就像它正在發生。看到這樣的畫面:
這是怎麼回事?