/// <summary> /// 该方法是线程安全的 /// </summary> /// <param name="status"></param> public void AddStatus(TitleBarStatus status) { lock (_syncStatus) { var g = GetImage(status); AddStatus(status, g); } }
/// <summary> /// 该方法是线程安全的 /// </summary> /// <param name="targetName"></param> /// <param name="status"></param> public void ReplaceOrAddStatus(string targetName, TitleBarStatus status) { lock (_syncStatus) { var g = GetImage(status); if (!ReplaceStatus(targetName, g)) { AddStatus(status, g); } } }
/// <summary> /// 该方法是线程安全的 /// </summary> /// <param name="targetName">需要被替换的状态名称</param> /// <param name="status"></param> public void ReplaceStatus(string targetName, TitleBarStatus status) { lock (_syncStatus) { var g = GetImage(status); for (var i = 0; i < _status.Children.Count; i++) { var c = _status.Children[i] as FrameworkElement; var s = c.DataContext as TitleBarStatus; if (s.Name == targetName) { _status.Children[i] = g; break; } } } }
public void AddStatus(TitleBarStatus status, ImagePro g) { bool finded = false; foreach (FrameworkElement c in _status.Children) { var s = c.DataContext as TitleBarStatus; if (s.Name == status.Name) { finded = true; break; } } if (!finded) { _status.Children.Insert(0, g); } }
private static ImagePro GetImage(TitleBarStatus status) { var g = new ImagePro() { Opacity = 0.5, Height = status.IconHeight, Width = status.IconWidth, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 5, 0), Source = status.Icon, }; g.ToolTip = new ToolTipText() { Description = status.Description }; g.DataContext = status; return(g); }