Reputation: 410
I have a Border which Content ComboBox, Now i want to change the Backround of the Border when the ComboBox get the Focus!!!
I have tried this code but it's not work :(
<Border CornerRadius="4" Margin="6,2,2,2" >
<StackPanel Orientation="Horizontal" x:Name="Tester">
<Label Content=" Signature :" Margin="10,0,0,0" FontFamily="Times New Roman" FontWeight="Normal" FontSize="14" ToolTip="You can join a file text containing your query with simple drag and drop of file here"/>
<ComboBox x:Name="Signatures" Margin="2,4,4,4" IsSynchronizedWithCurrentItem="False" FontWeight="Normal" FontFamily="Times New Roman" Width="180" IsTextSearchEnabled="True" IsEditable="True" FontSize="14" MouseDoubleClick="Signatures_MouseDoubleClick" MouseLeftButtonDown="Signatures_MouseDoubleClick" >
<ComboBoxItem Content="Serializable" HorizontalAlignment="Left" FontWeight="Normal" />
<ComboBoxItem Content="Comparable" HorizontalAlignment="Left"/>
<ComboBoxItem Content="CharSequence" HorizontalAlignment="Left"/>
<ComboBoxItem Content="Number" HorizontalAlignment="Left"/>
<ComboBoxItem Content="String" HorizontalAlignment="Left"/>
<ComboBoxItem Content="long" HorizontalAlignment="Left"/>
<ComboBoxItem Content="short" HorizontalAlignment="Left"/>
<ComboBoxItem Content="integer" HorizontalAlignment="Left"/>
<ComboBoxItem Content="double" HorizontalAlignment="Left"/>
<ComboBoxItem Content="float" HorizontalAlignment="Left"/>
<ComboBoxItem Content="byte" HorizontalAlignment="Left"/>
<ComboBoxItem Content="boolean" HorizontalAlignment="Left"/>
<ComboBoxItem Content="void" HorizontalAlignment="Left"/>
</ComboBox>
</StackPanel>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{x:Null}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Signatures, Path=IsFocused}" Value="True">
<Setter Property="Background" Value="BurlyWood"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
Can you help me please!
Upvotes: 1
Views: 319
Reputation: 13354
The issue is that the focus is not exactly on your ComboBox
but on a sub-element and AFAIK WPF is not able to tell you if the focus is within an element.
So you should add more DataTrigger
s:
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Signatures,Path=IsFocused}" Value="True">
<Setter Property="Background" Value="BurlyWood"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Signatures,Path=IsSelectionBoxHighlighted}" Value="True">
<Setter Property="Background" Value="BurlyWood"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Signatures,Path=IsDropDownOpen}" Value="True">
<Setter Property="Background" Value="BurlyWood"/>
</DataTrigger>
Upvotes: 2