2010-12-30 15 views
3

IsEnabledがfalseのときにイメージの不透明度を.50にしたいとします。私は複数の例を見てきましたが、私はそれを動作させる方法を理解することができません。WPF XAML IsEnabled状態でイメージの不透明度を変更する

ここに私のカスタムコントロールの完全な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> 

答えて

16

あなたはできるスタイルのトリガーを経由してそのIsEnabledプロパティに夫婦ImageOpacityプロパティを次のように

<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> 

IsEnabledがfalseの場合、これはOpacity 0.5に設定します。 UserControlIsEnabledプロパティは継承すなわち性の結果として、画像を変更されたとき

ImageIsEnabledプロパティがトリガされ、それがあまりにも設定されたIsEnabled性質を有することになるので、ユーザーコントロールの子です。

+0

ありがとう、今私は理解し、私は他のプロパティを試してみます。 – Nick

関連する問題