【发布时间】:2020-04-25 21:55:00
【问题描述】:
我正在尝试将IsMouseOver 属性集上的ContentControl 的Content 更改为True。这是稍微缩短的代码:
<ContentControl Margin="2 0 6 0" Width="20" Height="20">
<Image>
<Image.Source>
<DrawingImage >
<DrawingImage.Drawing>
<GeometryDrawing>
// drawing here
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
<ContentControl.Style>
<Style>
<Style.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="ContentControl.Content">
<Setter.Value>
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
// Canvas here
</Viewbox>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
使用 Snoop,我确实可以检查 IsMouseOver 是否设置为 true,但 Content 永远不会改变。我在这里想念什么?是否可以使用触发器更改 Content 或 ContentControl?
【问题讨论】:
-
直接设置的内容值(通过将
<Image>标签放入ContentControl)比触发器中的Setter设置的值具有更高的优先级,因此触发器没有效果。