【发布时间】:2012-08-06 21:03:47
【问题描述】:
我正在尝试创建一个 on 事件操作,它可以重复用于许多对象。 为此,我将目标对象的名称存储在 Tag 属性中。 所以在事件被触发时:
private void ShowDeleteButton(object sender, System.Windows.Input.MouseEventArgs e)
{
Duration TimeToTake = new Duration(new TimeSpan(0,0,0,0,300));
DoubleAnimation ShowButton = new DoubleAnimation(0, 104, TimeToTake);
DoubleAnimation HideButton = new DoubleAnimation(104, 0, TimeToTake);
(sender as Rectangle).Tag.BeginAnimation(Button.WidthProperty, ShowButton);
}
显然使用 (sender as button).Tag 作为对象的名称将不起作用。那么如何将 tag 属性转换为目标对象的引用呢?
注意这是 WPF
谢谢
【问题讨论】: