2017-08-30 10 views
1

私はWPFを初めて使用しています。 TextBlockIsEnabledプロパティがfalseになると、ハイパーリンクの前景色を他の色(灰色など)に変更しようとしています。私の要求を達成するためにStyleを追加しますか?TextBlockのIsEnabledプロパティが変更されたときにハイパーリンクの色を変更するにはどうすればよいですか?

私はここで立ち往生している:

  <TextBlock Margin="0,150,0,0" 
         TextAlignment="Center" 
         Background="White" 
         IsEnabled="{Binding ShowProgressRing}"> 

       <Hyperlink x:Name="HyperLink" 
          Foreground="Blue" 
          TextDecorations="UnderLine" 
          FontSize="12" 
          FontWeight="SemiBold" 
          Command="{Binding Path=Command}" > 
        <Run Text="{Binding Path=HyperLinkText}"/> 
       </Hyperlink> 
      </TextBlock> 
+1

ForegroundプロパティをIsEnabledプロパティにバインドし、コンバータを使用して色を変更します。 –

+0

@VishalPrajapatiありがとうございます。私はこれがうまくいくと思います – ZigZig

答えて

2

ハイパーリンクが無効になったときに、無効のTextBlockと、それは

に行われていることができますので、それは、デフォルト(デフォルトフォアグラウンドがオーバーライドされていない場合)でグレーに色が変化
<TextBlock Margin="0,150,0,0" 
      TextAlignment="Center" 
      Background="White" 
      IsEnabled="{Binding ShowProgressRing}"> 

    <Hyperlink x:Name="HyperLink"     
       TextDecorations="UnderLine" 
       FontSize="12" 
       FontWeight="SemiBold" 
       Command="{Binding Path=Command}" > 
     <Run Text="{Binding Path=HyperLinkText}"/> 
    </Hyperlink> 
</TextBlock> 

ハイパーリンクがデフォルト以外のアクティブ/無効に色を持っている必要がある場合は、あなたがトリガーとハイパーリンクのスタイルを書くことができます。

<Hyperlink x:Name="HyperLink" 
      TextDecorations="UnderLine" 
      FontSize="12" 
      FontWeight="SemiBold" 
      Command="{Binding Path=Command}" > 

    <Run Text="{Binding Path=HyperLinkText}"/> 

    <Hyperlink.Style> 
     <Style TargetType="Hyperlink"> 
      <Setter Property="Foreground" Value="Blue"/> 
      <Style.Triggers> 
       <!--binding to the same view model property which sets IsEnabled--> 
       <DataTrigger Binding="{Binding ShowProgressRing}" Value="False"> 
        <Setter Property="Foreground" Value="Gray"/> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 
    </Hyperlink.Style> 

</Hyperlink> 
関連する問題