마우스 오버 하이라이트 스타일은 1 초 후 기본값으로 돌아 오는 스타일 (에어로로 인해?)
문제
나는 UI의 나머지 부분과 일치하도록 콤보 박스를 스타일링하려고 노력했지만 ISMouseOver 강조점에 문제가 있습니다. 그것은 내가 지정한 색상으로 1 초 동안 강조한 다음 기본 색상으로 다시 사라지고, 멋진 효과는 있지만 내가하려는 것은 아닙니다. 여기 내 스타일이 있습니다.
<Style TargetType="ComboBox">
<Style.Triggers>
<Trigger Property="ComboBox.IsMouseOver" Value="True">
<Setter Property = "Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
배경색을 유지하려면 어떻게해야합니까?
해결책
문제는 실제로 Combobox의 기본 템플릿 때문입니다. 사용하는 경우 반사기 PresentationFramework.aero 어셈블리를 열려면 ButtonChrome 클래스를 살펴볼 수 있습니다. rendermouseoverchanged라고 불리는 방법이 빨간 배경을 숨기고 있습니다.
많은 작업이지만 Combobox의 경우 적어도 Combobox의 기본 템플릿을 무시하고 싶을 것입니다. Combobox Temlpate가 사용하여 어떤 모습인지에 대한 기본 아이디어를 얻을 수 있습니다. 템플릿을 보여주세요 또는 혼합하다.
동일한 스타일을 사용하여 템플릿을 무시할 수 있습니다.
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<!-- Template Here -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
다른 팁
WPF Visual Studio Designer에서 기본 템플릿의 사본을 가져온 다음 Comboboxreadonlytogglebutton 스타일에서 Buttonchrome 섹션을 언급하고 테두리로 바꾸어이 동작을 무시할 수 있습니다. 다음은 솔루션을 찾은 사이트에 대한 링크입니다. http://www.scriptscoop.net/t/d346cf01d844/cc-wpf-combobox-over-color.html
여기 내 코드 스 니펫이 있습니다
<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<!-- Replace the ButtonChrome - this eliminated the following
problem: When the mouse was moved over the ComboBox
the color would change to the color defined in ___ but
then would
immediately change to the default Aero blue
gradient background of 2 powder blue colors -
Had to comment out the
below code and replace it as shown
<Themes:ButtonChrome x:Name="Chrome" BorderBrush=" {TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
</Grid>
</Themes:ButtonChrome>-->
<!-- Here is the code to replace the ButtonChrome code -->
<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
</Grid>
</Border>
<!-- End of code to replace the Button Chrome -->
또한 배경색을 Darkorange로 변경하기 위해 코드를 추가했습니다.
<!-- Hover Code - Code that was added to change the ComboBox background
color when the use hovers over it with the mouse -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkOrange"></Setter>
</Trigger>
<!-- Hover Code - End -->