私はこれの初心者であり、WPFとXAMLがどのように機能するかを理解しようとしています。次のスニペットは、Nathans Unleashed 4.0の本からの(些細な変更)です。[OK]ボタンに挿入しました:
<Button.Style>
<Style TargetType=”{x:Type Button}”>
<Style.Triggers>
<Trigger Property=”IsMouseOver” Value=”True”>
<Setter Property=”Background” Value=”Yellow”/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
これをXAMLクランシャーで実行し、マウスを[OK]ボタンの上に移動すると、ボタンは背景色を黄色(細かい)に変更しますが、マウスがボタンの上にある場合でも、すぐに元の値にリセットされます-理由これは?マウスがボタンから離れるまで黄色のままになると思います。これはXAMLクランシャーの問題ですか、それとも私の期待は間違っていますか?
編集(コメントへの応答):これは、ネイサンの本から取られた完全なウィンドウです:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="About WPF Unleashed" SizeToContent="WidthAndHeight"
Background="OrangeRed">
<StackPanel>
<Label FontWeight="Bold" FontSize="20" Foreground="White">
WPF Unleashed (Version 3.0)
</Label>
<Label>© 2006 SAMS Publishing</Label>
<Label>Installed Chapters:</Label>
<ListBox>
<ListBoxItem>Chapter 1</ListBoxItem>
<ListBoxItem>Chapter 2</ListBoxItem>
</ListBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button MinWidth="75" Margin="10">Help</Button>
<Button MinWidth="75" Margin="10">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
OK
</Button>
</StackPanel>
<StatusBar>You have successfully registered this product.</StatusBar>
</StackPanel>
</Window>