【发布时间】:2015-02-12 18:15:22
【问题描述】:
当 Opacity 值为 0.0 时,我想更改 TextBlock.Text。由情节提要上的 DoubleAnimation 为 TextBlock 设置动画(不透明度在 3 秒内从 1.0 渐变到 0.0,重复和自动反转)。这甚至可以使用 DoubleAnimation 或 Storyboard Events 吗?我尝试在 CurrentStateInvalidated 和 CurrentTimeInvalidated 中更改 TextBlock 的 Text 属性,但它们只触发一次。
编辑:这是我到目前为止的触发器。这不会产生预期的结果。
public MainWindow()
{
InitializeComponent();
this.Loaded += delegate
{
Style st = new Style();
st.TargetType = typeof(TextBlock);
DataTrigger t = new DataTrigger();
t.Value = (double)0.0;
t.Binding = new Binding()
{
Path = new PropertyPath("Opacity"),
RelativeSource = RelativeSource.Self
};
Setter se = new Setter();
se.Property = TextBlock.TextProperty;
se.Value = GetTickerString();
t.Setters.Add(se);
st.Triggers.Clear();
st.Triggers.Add(t);
txblkTickerText1.Style = st;
};
}
【问题讨论】:
-
您可以在不透明度上使用触发器并在不透明度 == 0 时为文本放置一个设置器