【发布时间】:2013-09-09 13:20:58
【问题描述】:
我为视图框做了一个触发器,当鼠标悬停在视图框上时,内容会发生变化。
这可行,但由于视图框的内容很小,我希望在视图框周围有一个边框,该边框也会触发鼠标悬停事件。
<Viewbox Width="50" x:Name="ActionIconBox1" Height="40.5">
<ContentControl>
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Content" Value="{StaticResource action_message}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Viewbox,AncestorLevel=1}, Path=IsMouseOver}" Value="True" >
<Setter Property="Content" Value="{StaticResource action_message_focus}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</Viewbox>
这仅在鼠标在内容控件上时有效,在鼠标进入 Viewbox 时无效。
资源是一个画布
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_message" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="38" Height="39.75" Canvas.Left="19" Canvas.Top="22" Stretch="Fill" Fill="#FF1BA1E2" Data="F1 M 33,51L 36.4167,61.75L 24,51L 19,51L 19,22L 57,22L 57,51L 33,51 Z "/> </Canvas>
为什么绑定不起作用?
【问题讨论】:
-
究竟什么“不起作用”?另外,您是否尝试从
Trigger链接到appbar_messageCanvas?你可能会遇到问题,因为你在Trigger中将其称为action_message。 -
只有当鼠标在内容控件上时,内容才会改变,图像本身。但不是当鼠标在视图框上时。是的,不用担心只是复制粘贴错误。在我的代码中,链接是正确的。
-
viewbox 和 contentcontrol 之间有边距吗?
标签: c# wpf wpf-controls