我尝试对图像进行缩放,我创建样式,这里是:
<Style x:Key="ZoomImage" TargetType="{x:Type Image}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
我在窗口中应用这种风格:
<Grid Name="RootGrid" Margin="4,4,4,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Name="InfoGrid" Grid.Column="0" Margin="4,4,4,4">
<Grid.RowDefinitions>
<RowDefinition Height="150"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="150"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Name="UserPanel" Grid.Row="0" Margin="4,4,4,4">
<Border BorderThickness="1"
BorderBrush="Black"
Margin="1,1,1,1"
Background="WhiteSmoke">
<Image Name="UserImage"
<!--Apply style -->
Style="{StaticResource ZoomImage}"
Margin="4,4,4,4">
<Image.Source>
<MultiBinding Converter="{StaticResource imageConvertor}">
<Binding Path="ProfilePhoto"/>
<Binding Path="Status" UpdateSourceTrigger="PropertyChanged"/>
</MultiBinding>
</Image.Source>
</Image>
</Border>
</StackPanel>
</Grid>
但是不能做变焦,哪里可能有问题?
我使用Guy advance:
<Trigger Property="IsHitTestVisible" Value="True">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
</Setter.Value>
</Setter>
</Trigger>
但是,如果鼠标结束,图像不会缩放。
答案 0 :(得分:0)
默认情况下,图像不是命中测试可见 - 图像中的IsHitTestVisible =“True”,或者等效的设置器可以完成工作。