Here is a way to update the bindings in specific controls on an event like button click, in our task bars. You could use this approach on other controls' bindings, besides our task bars as well:
public void RefreshBindings(DependencyObject element, bool recurse)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(element,
new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }))
{
DependencyPropertyDescriptor dpd =
DependencyPropertyDescriptor.FromProperty(pd);
if (dpd != null)
{
if (BindingOperations.IsDataBound(element, dpd.DependencyProperty))
{
BindingOperations.GetBindingExpression(element, dpd.DependencyProperty).UpdateTarget();
}
}
}
if (recurse)
{
List<FrameworkElement> Children = new List<FrameworkElement>();
Extensions.GetChildren<FrameworkElement>(element, ref Children, true, false);
foreach (FrameworkElement item in Children)
{
RefreshBindings(item, false);
}
}
}