我的问题可能听起来有点类似于 这个问题
当我的自定义 UserControl 的 DependencyProperty 更改时,我有一个通知栏会经历某些动画。下面是代码实现:
public string StatusBarText
{
get { return (string)GetValue(StatusBarTextProperty); }
set { SetValue(StatusBarTextProperty, value); }
}
public static readonly DependencyProperty StatusBarTextProperty =
DependencyProperty.Register("StatusBarText", typeof(string), typeof(WorkspaceFrame), new FrameworkPropertyMetadata(null, StatusBarTextChangedCallBack));
private static void StatusBarTextChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(Convert.ToString(e.NewValue)))
{
var workspaceFrame = d as WorkspaceFrame;
if (null == workspaceFrame)
return;
var storyboard = workspaceFrame.FindResource("notificationBarAnimation") as Storyboard;
if (null == storyboard)
return;
var statusBar = workspaceFrame.Template.FindName("PART_StatusBar", workspaceFrame) as Border;
if (null == statusBar)
return;
//Run the animation
storyboard.Begin(statusBar);
}
}
这是动画的边框:
<Border x:Name="PART_StatusBar" Margin="5" BorderThickness="2" VerticalAlignment="Top"
DataContext="{Binding Path=StatusText}" Opacity="0"
Visibility="{Binding Path=Opacity, Mode=OneWay, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToVis}}"
BorderBrush="{StaticResource StatusMessageBackBrush}">
<Border.Background>
<SolidColorBrush Color="{StaticResource StatusMessageBackColor}" Opacity="0.7"/>
</Border.Background>
<TextBlock Margin="10" FontSize="17" Foreground="{StaticResource BlackColorBrush}" Text="{Binding}">
</TextBlock>
</Border>
您现在可能很清楚,此 DP 绑定到一个 VM 属性,该属性在设置时会触发 PropertyChangedNotification(属于 INotifyProeprtyChanged)。现在的问题是,仅当 DP 的旧值和新值发生一些变化时才会调用StatusBarTextChangedCallBack 。有没有办法强制它运行?如果没有,有什么办法吗?我需要一遍又一遍地显示相同的通知。动画应该会触发。
问候,
詹姆士