저는 초보자이며 WPF 및 XAML의 작동 방식을 이해하려고합니다. 다음 스 니펫은 Nathans Unleashed 4.0 서적 (사소한 수정)입니다. 나는 확인 버튼으로 삽입 : 내가 XAML의 crunsher에서이 프로그램을 실행하고 확인 버튼 위에 마우스를 이동하면IsMouseOver가 일시적으로 배경색 변경 만 수행합니다.
<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 crunsher에 문제가 있습니까? 아니면 내 기대가 잘못 되었습니까?
편집 (주석에 응답) :
<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>
귀하의 기대는 완벽합니다. 귀하의 코드를 복사 했으므로 예상대로 작동합니다. –
단추에 사용자 지정 서식 파일을 사용합니까? –
@ ErikÖjebo 아니, 내 지식에 그것은 단순한 버튼 일 뿐이다. 더 나쁜 것은 'Background'대신 'Foreground'를 사용하면 예상대로 작동한다는 것입니다. 즉, 마우스가 버튼을 벗어날 때까지 전경색이 유지됩니다. – Thomas