0

「見た目」を無効にする方法を知っているカスタムコンテンツを使用してSilverlightボタンを作成する最も簡単な方法は何ですか?つまり、設定IsEnabled="False"するとグレー表示になります。

カスタムコンテンツは、テキストと画像の非常にシンプルなものになります。

これは、以前にWPFアプリケーションで、ContentBlockとImageを含むStackPanelにコンテンツを設定することで非常に簡単に実行できました。次に、画像にスタイルトリガーを実装して、有効になっていないときに画像をグレー表示のバージョンに変更しました。テキスト自体の色が変わりました。

私が知る限り、Silverlightでボタンを無効にすると、カスタムコンテンツが完全に消えます。

どんな助けでも大歓迎です。

乾杯、アンドレイ。

4

2 に答える 2

3

Button のテンプレートを変更していないと仮定すると、Button の既定のコントロール テンプレートは、VisualStateManager を使用して、ボタン内のコンテンツの上に透明度 50% の白い四角形をオーバーレイします。これにより、コンテンツが「洗い流された」外観になります。

テンプレートを置き換えた場合は、この動作を複製する必要があります。Silverlight には Style トリガーがないため、VisualStateManager を使用する必要があります。エクスプレッション ブレンドはありますか? その場合は、デザイナーにボタンをドラッグして既定のコントロール テンプレートを表示できます。右クリック -> テンプレートの編集 -> コピーを編集します。

編集

Blend によって抽出された Button のデフォルト コントロール テンプレートを含めました。VisualStateManager の Disabled 状態に注意してください。

<ControlTemplate TargetType="Button">
  <Grid>
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">
        <VisualState x:Name="Normal"/>
        <VisualState x:Name="MouseOver">
          <Storyboard>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
              <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF"/>
            </ColorAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
        <VisualState x:Name="Pressed">
          <Storyboard>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#FF6DBDD1"/>
            </ColorAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
              <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#D8FFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#8CFFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
              <SplineColorKeyFrame KeyTime="0" Value="#3FFFFFFF"/>
            </ColorAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
        <VisualState x:Name="Disabled">
          <Storyboard>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity">
              <SplineDoubleKeyFrame KeyTime="0" Value=".55"/>
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
      <VisualStateGroup x:Name="FocusStates">
        <VisualState x:Name="Focused">
          <Storyboard>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity">
              <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
        <VisualState x:Name="Unfocused"/>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border
      x:Name="Background"
      Background="White"
      BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}"
      CornerRadius="3">
      <Grid Margin="1" Background="{TemplateBinding Background}">
        <Border x:Name="BackgroundAnimation" Opacity="0" Background="#FF448DCA"/>
        <Rectangle x:Name="BackgroundGradient">
          <Rectangle.Fill>
            <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
              <GradientStop Color="#FFFFFFFF" Offset="0"/>
              <GradientStop Color="#F9FFFFFF" Offset="0.375"/>
              <GradientStop Color="#E5FFFFFF" Offset="0.625"/>
              <GradientStop Color="#C6FFFFFF" Offset="1"/>
            </LinearGradientBrush>
          </Rectangle.Fill>
        </Rectangle>
      </Grid>
    </Border>
    <ContentPresenter
      x:Name="contentPresenter"
      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
      Margin="{TemplateBinding Padding}"
      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
      Content="{TemplateBinding Content}"
      ContentTemplate="{TemplateBinding ContentTemplate}"/>
    <Rectangle
      x:Name="DisabledVisualElement"
      Fill="#FFFFFFFF"
      RadiusX="3"
      RadiusY="3"
      IsHitTestVisible="false"
      Opacity="0"/>
    <Rectangle
      x:Name="FocusVisualElement"
      Stroke="#FF6DBDD1"
      StrokeThickness="1"
      RadiusX="2"
      RadiusY="2"
      Margin="1"
      IsHitTestVisible="false"
      Opacity="0"/>
  </Grid>
</ControlTemplate>
于 2010-04-07T04:44:21.393 に答える
1

ボタンの Opacity プロパティを少し下げると、無効に見えるようにするのに役立つ場合があります。

于 2010-04-07T06:05:26.690 に答える