【发布时间】:2018-05-29 10:49:21
【问题描述】:
我有一个列跨度为 2 的矩形,在网格行中有一个标签和一个按钮。
<Rectangle Grid.Row="2" Grid.ColumnSpan="2"></Rectangle>
<Label Grid.Row="2" Grid.Column="0">Product Two</Label>
<Button Grid.Row="2" Grid.Column="1" Click="Button2_Click">Select</Button>
当鼠标悬停在行上时,我打算更改矩形的填充颜色。但似乎鼠标悬停在标签或按钮上会阻止鼠标悬停在矩形上,这与 HTML 不同。
这是默认行为吗?什么是正确的方法?
编辑,网格的完整 XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.Resources >
<Style TargetType="{x:Type Rectangle}">
<Setter Property="Fill" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" Value="#44000000"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Label Grid.Row="0" Grid.Column="0" FontWeight="Bold">Product</Label>
<Label Grid.Row="0" Grid.Column="1">Choose</Label>
<Rectangle Grid.Row="1" Grid.ColumnSpan="2"></Rectangle>
<Label Grid.Row="1" Grid.Column="0">Product One</Label>
<Button Grid.Row="1" Grid.Column="1" Click="Button1_Click">Select</Button>
</Grid>
【问题讨论】:
-
请告诉我们
grid这3个项目在里面。 -
为网格添加了完整的 xaml