当 IsEnabled 为 false 时,我希望图像的不透明度为 0.50。我一直在查看多个示例,但仍然无法掌握如何使其发挥作用。
这是我的自定义控件的完整 XAML。任何帮助将不胜感激。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="test.StopButtonControl"
x:Name="UserControl"
d:DesignWidth="85" d:DesignHeight="85">
<Grid x:Name="LayoutRoot">
<Image x:Name="StopButtonUI" Source="Images/stop.png" Stretch="Fill" MouseUp="StopButtonClick"/>
</Grid>
</UserControl>
您可以将Image
's Opacity
其财产IsEnabled
通过样式触发器属性如下:
<Grid x:Name="LayoutRoot">
<Image x:Name="StopButtonUI" Source="Images/stop.png" >
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
这将设置Opacity
到 0.5 时IsEnabled
是假的。
The Image
's IsEnabled
属性将被触发时UserControl
有它的IsEnabled
属性因属性继承而更改,即图像是用户控件的子级,因此它将具有其IsEnabled
属性也设置了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)