Tuesday, 10 September 2013

ItemTemplate: How can I know if item is selected?

ItemTemplate: How can I know if item is selected?

I have a ListBox that use my custom ItemTemplate. I want to set Visibility
property in my TextBlock (inside my template) depending on selected item.
I think of doing it using triggers. But how can I know inside my template
if current item is selected or not?
<DataTemplate x:Key="myTemplate">
<StackPanel Orientation="Horizontal">
<Image Tag="{Binding priority}" Loaded="SetIconPriority"/>
<Image Tag="{Binding alarm}" Loaded="SetIconAlarm"/>
<!-- I want this TextBlock to be visible only when item is
selected -->
<TextBlock Text="{Binding description}"/>
</StackPanel>
</DataTemplate>

No comments:

Post a Comment