2017-08-08 41 views
1

マウスオーバーするときにボタンの背景を#f5f5f5に変更したいだけです。
WPFには簡単にできるトリガ機能があります。
私はUWPがこれ以上何のトリガーを持っていないが、他の機能との代わりに、この質問のようなことを聞​​いたのに対し:UWPでマウスオーバーするとボタンの背景を変更するにはどうすればよいですか?

<ControlTemplate TargetType="Button" x:Key="ButtonControlTemplate"> 
      <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Name="ButtonBorder" Background="{TemplateBinding Background}">     
       <ContentPresenter FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Foreground="{TemplateBinding Foreground}"></ContentPresenter> 
      </Border> 
      <Interactivity:Interaction.Behaviors> 
       <Core:DataTriggerBehavior Binding="{Binding PointerMovedEvent, ElementName=ButtonBorder}" Value="true"> 
        <Core:ChangePropertyAction TargetObject="{Binding ElementName=ButtonBorder}" PropertyName="Background" Value="#f5f5f5" /> 
       </Core:DataTriggerBehavior> 
      </Interactivity:Interaction.Behaviors> 
     </ControlTemplate> 


プログラム:
Trigger element (XAML) is not supported in a UWP project

私はチュートリアルとしてDataTriggerBehaviorでそれをやりました正常に動作しますが、背景を変更することはできません。
ああ、私の神。
VisualStateも試しましたが、チュートリアルが見つからないため、使用方法がわかりません。
さらに、マイクロソフトがなぜトリガーを使用しないのかほとんど知ることはできません。
問題の解決方法を教えてください。
ありがとうございました!

答えて

2

XAML Behavior SDKのトリガーまたはビヘイビアを使用できますが、代わりにButtonのカスタムスタイルを使用します。 default style内のPointerOver状態で色を変更するだけです。

<VisualState x:Name="PointerOver"> 
    <Storyboard> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="RootGrid"> 
      <DiscreteObjectKeyFrame KeyTime="0" Value="#f5f5f5"/> 
     </ObjectAnimationUsingKeyFrames> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter"> 
      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPointerOver}"/> 
     </ObjectAnimationUsingKeyFrames> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> 
      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPointerOver}"/> 
     </ObjectAnimationUsingKeyFrames> 
     <PointerUpThemeAnimation Storyboard.TargetName="RootGrid"/> 
    </Storyboard> 
</VisualState> 

また、あなたはあなたのApp.xaml内部ButtonBackgroundPointerOverを上書きすることができます。

​​
+1

もう一度お手伝いをしてくれてありがとう。私はVisualStateについてもっと知りたいと思う。 –

関連する問題