mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-27 15:15:00 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
52
src/Views/Controls/Badge.cs
Normal file
52
src/Views/Controls/Badge.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SourceGit.Views.Controls {
|
||||
|
||||
/// <summary>
|
||||
/// 徽章
|
||||
/// </summary>
|
||||
public class Badge : Border {
|
||||
private TextBlock label = null;
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
"Label",
|
||||
typeof(string),
|
||||
typeof(Border),
|
||||
new PropertyMetadata("", OnLabelChanged));
|
||||
|
||||
public string Label {
|
||||
get { return (string)GetValue(LabelProperty); }
|
||||
set { SetValue(LabelProperty, value); }
|
||||
}
|
||||
|
||||
public Badge() {
|
||||
Width = double.NaN;
|
||||
Height = 18;
|
||||
CornerRadius = new CornerRadius(9);
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
Background = FindResource("Brush.Badge") as Brush;
|
||||
Visibility = Visibility.Collapsed;
|
||||
|
||||
label = new TextBlock();
|
||||
label.FontSize = 10;
|
||||
label.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
label.Margin = new Thickness(9, 0, 9, 0);
|
||||
Child = label;
|
||||
}
|
||||
|
||||
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
Badge badge = d as Badge;
|
||||
if (badge != null) {
|
||||
var text = e.NewValue as string;
|
||||
if (string.IsNullOrEmpty(text) || text == "0") {
|
||||
badge.Visibility = Visibility.Collapsed;
|
||||
} else {
|
||||
badge.label.Text = text;
|
||||
badge.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue