2016-09-27 9 views
2

コントロールにホバー効果を追加したい(境界線や背景色を変更する)。私は、このいずれかのようにそれについて多くの答えを発見した: WPF: On Mouse hover on a particular control, increase its size and overlap on the other controlsWPF MaterialDesignのカスタムコントロールをホバリングする

問題は、私はカスタムコントロールを使用しています(私は特にWPF用materialdesignを使用しています)です。私はTargetTypeを置くべきものを知らない。

更新日:ここまでは私がこれまで行ってきたことです。無関係なコードを削除しました。

私が言ったように、私はTargetTypeを置くべきか分からないので、Controlを入れようとしましたが、動作しません。

<md:Card 
    Margin="4 4 4 4" 
    Width="100" 
    Height="220" 
    > 
    <md:Card.Style> 
     <Style TargetType="{x:Type Control}"> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="Background" Value="Red"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </md:Card.Style> 
    <Grid> 
    </Grid> 
</md:Card> 
+0

は、あなたがそれ自分で試してみるましたか?コードを表示した方がより便利です。 – esote

+0

私は自分の質問を編集しました。 – someone

答えて

3

これを試してみてください:

<Window 
    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" 
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" 
    xmlns:conv="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf" 
    xmlns:local="clr-namespace:WpfApplication1" 
    x:Class="WpfApplication1.MainWindow" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="300" Width="300"> 
<Window.Resources> 


    <Style x:Key="CardStyle1" TargetType="{x:Type materialDesign:Card}"> 
     <Setter Property="Background" Value="#2fff0000"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type materialDesign:Card}"> 
        <Grid Margin="{TemplateBinding Margin}" Background="Transparent"> 
         <AdornerDecorator> 
          <AdornerDecorator.CacheMode> 
           <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/> 
          </AdornerDecorator.CacheMode> 
          <Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialDesign:ShadowAssist.ShadowDepth), Converter={x:Static conv:ShadowConverter.Instance}}" 
        CornerRadius="{TemplateBinding UniformCornerRadius}"> 
           <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" 
         x:Name="PART_ClipBorder" 
         Clip="{TemplateBinding ContentClip}" /> 
          </Border> 
         </AdornerDecorator> 
         <ContentPresenter 
      x:Name="ContentPresenter"      
      Margin="{TemplateBinding Padding}" 
      Clip="{TemplateBinding ContentClip}" 
      Content="{TemplateBinding ContentControl.Content}" 
      ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" 
      ContentTemplateSelector="{TemplateBinding ContentControl.ContentTemplateSelector}" 
      ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"> 
         </ContentPresenter> 
        </Grid> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsMouseOver" Value="True"> 
          <Setter TargetName="PART_ClipBorder" Property="Background" Value="#4fff0000" /> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

</Window.Resources> 
<Grid> 

    <materialDesign:Card Style="{DynamicResource CardStyle1}" 
         Content="My Sample Card" 
         HorizontalAlignment="Center" 
         Margin="0" 
         VerticalAlignment="Center" 
         Width="100" 
         Height="100" /> 

</Grid> 

enter image description here

+0

ありがとうございます。できます。 – someone

+0

すみません、忘れました。私はそれまでに投票に投票する特権を持っていません。 – someone

関連する問題