【发布时间】:2009-10-27 01:47:51
【问题描述】:
我无法让以下工作。目标是改变用户控件的 ZIndex 当鼠标悬停在其内容上时。
使用像“Background”这样的简单属性代替 ZIndex 也不起作用。编译器抱怨“无法将值 'Grid.IsMouseOver' 分配给属性 'Property'。对象引用未设置为对象的实例。” (编译启动项目后)。
有人可以提供一个可以改变不同控件的某些属性的触发器的工作示例吗?
<UserControl x:Class="ImageToolWPF.Controls.sample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<UserControl.Triggers>
<Trigger SourceName="viewPort" Property="Grid.IsMouseOver" Value="True">
<Setter TargetName="me" Property="UserControl.Panel.ZIndex" Value="2" />
</Trigger>
</UserControl.Triggers>
<Border Name="border" CornerRadius="3,3,3,3" BorderThickness="3" BorderBrush="Green">
<Grid Name="viewPort">
<Label Name="labelTop" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" Background="#a0ffffff" Padding="4"/>
</Grid>
</Border>
</UserControl>
【问题讨论】: