8,734
社区成员
发帖
与我相关
我的任务
分享
public class TextBlockTest :TextBlock
{
TranslateTransform tt;
bool animated;
public TextBlockTest()
: base()
{
tt = new TranslateTransform();
this.RenderTransform = tt;
animated = false;
this.MouseEnter += new MouseEventHandler(TextBlockTest_MouseEnter);
}
void TextBlockTest_MouseEnter(object sender, MouseEventArgs e)
{
if (tt == null)
return;
if (animated)
return;
Duration duration = new Duration(TimeSpan.FromSeconds(0.5));
DoubleAnimation da = new DoubleAnimation(0,-30, duration);
da.AutoReverse = true;
tt.BeginAnimation(TranslateTransform.XProperty, da);
animated = true;
}
}
<ListBox x:Name="ListBoxTest">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="50" Background="AliceBlue">
<local:TextBlockTest Text="{Binding}"></local:TextBlockTest>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
string[] source = new string[] { "Alpha", "Beta","Crow"};
ListBoxTest.ItemsSource = source;