C# Silverlight触发器设置可见性

C# Silverlight触发器设置可见性,c#,.net,silverlight,C#,.net,Silverlight,我有一个带有修改过的数据模板的列表框(它包含一个超链接按钮和每个项目的文本框)。我希望按钮在默认情况下不可见,但在鼠标悬停在特定列表框项目上时变为可见。到目前为止,我尝试过的XAML不起作用,我也不知道为什么(不起作用的意思是它无法编译) 您得到了什么编译错误?我可以编译它,但我不希望它工作 您似乎是通过在列表框的模板中定义另一个列表框来定义列表框的。这是故意的吗?我希望基本项模板如下所示(网格可选): 谢谢,您有不依赖于expression blend的版本吗?也就是说,不依赖于“”?@Ben

我有一个带有修改过的数据模板的列表框(它包含一个超链接按钮和每个项目的文本框)。我希望按钮在默认情况下不可见,但在鼠标悬停在特定列表框项目上时变为可见。到目前为止,我尝试过的XAML不起作用,我也不知道为什么(不起作用的意思是它无法编译)


您得到了什么编译错误?我可以编译它,但我不希望它工作

您似乎是通过在列表框的模板中定义另一个列表框来定义列表框的。这是故意的吗?我希望基本项模板如下所示(网格可选):


谢谢,您有不依赖于expression blend的版本吗?也就是说,不依赖于“”?@Ben:是的,我确实使用blend编写了这个示例,但这些DLL是表达式blend SDK的一部分。你实际上不需要混合。干杯。@Ben:或者,把故事板放回内联状态(就像你在例子中看到的那样)。我只是将它们分开,以便它们仍然可以在Blend中编辑。
 <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>
    <ListBox Name="lstTest" ItemsSource="{Binding}>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <StackPanel VerticalAlignment="Top">
                        <TextBlock Text="{Binding Name}"/>
                        <HyperlinkButton Content="Edit" />
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:System="clr-namespace:System;assembly=mscorlib" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
    x:Class="SilverlightApplication1.SilverlightTrigger"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <ListBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.Resources>
                            <Storyboard x:Name="Storyboard1">
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="hypEdit">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.5">
                                        <DiscreteObjectKeyFrame.Value>
                                            <Visibility>Visible</Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                            <Storyboard x:Name="Storyboard2">
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="hypEdit">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.5">
                                        <DiscreteObjectKeyFrame.Value>
                                            <Visibility>Collapsed</Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </Grid.Resources>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseEnter">
                                <ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="MouseLeave">
                                <ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard2}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <StackPanel VerticalAlignment="Top">
                            <TextBlock TextWrapping="Wrap" Text="{Binding Name}" d:LayoutOverrides="Width"/>
                            <HyperlinkButton x:Name="hypEdit" Content="Edit" d:LayoutOverrides="Width" Visibility="Collapsed"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>