Wpf ListBox Trigger not working for IsFocused Property.
Posted
by viky
on Stack Overflow
See other posts from Stack Overflow
or by viky
Published on 2009-11-18T05:19:39Z
Indexed on
2010/03/20
15:41 UTC
Read the original article
Hit count: 604
I want to style my ListBox and displaying some Border around it, i want to hide this Border when ListBox gets focus,
<Trigger Property="IsFocused" Value="True">
<Setter Property="Visibility" TargetName="border" Value="Collapsed"/>
</Trigger>
Same thing i m using in TextBox also and it is working properly, why this Trigger not working for ListBox?
Edit:
i am having this Style for my ListBox
<ControlTemplate TargetType="{x:Type local:ListBox}">
<Border SnapsToDevicePixels="true" x:Name="Bd" CornerRadius="5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
<Grid>
<local:ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</local:ScrollViewer>
<Border CornerRadius="5" Background="Red" x:Name="border">
<TextBlock VerticalAlignment="Center" FontWeight="Bold" Foreground="White" Text="{TemplateBinding Message}" FontFamily="Courier New" />
</Border>
</Grid>
</Border>
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Visibility" TargetName="border" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
© Stack Overflow or respective owner