I have a ListBox with an altered datatemplate (it contains a hyperlinkbutton and a textbox for each item). I would like the button to not be visible by default, but to turn visible when the mouse is hovered over that particular list box item. The XAML I have tried so far doesn’t work and i can’t figure out why (by doesn’t work I mean it fails to compile).
<ListBox Name="lstTest">
<ListBox.Template>
<ControlTemplate>
<ListBox ItemsSource="{Binding}">
<StackPanel >
<TextBlock Text="{Binding Path=Name}"/>
<HyperlinkButton Name="hypEdit" Content="Edit" Visibility="Collapsed" />
</StackPanel>
<ListBox.Triggers>
<EventTrigger RoutedEvent="ListBoxItem.MouseEnter" >
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="hypEdit" Storyboard.TargetProperty="Visibility"
From="Collapsed" To="Visible" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListBox.Triggers>
</ListBox>
</ControlTemplate>
</ListBox.Template>
</ListBox>
What compile error do you get? I can compile it, but I would not expect it to work.
You seem to have defined the listbox by defining another listbox within its template. Was that intentional? I would have expected the basic item template to look like this (grid optional):
Below is a complete working example of what I think you were after:
Feel free to tweak to your own requirements.