private static void SetImageSource(AvatarBox ab, ImageSource source) { if (ab.image != null) { ab.image.Source = source; } }
private static void SetInnerMargin(AvatarBox ab, double newValue) { if (ab.innerBG != null) { ab.innerBG.Margin = new Thickness(newValue); } }
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AvatarBox ab = d as AvatarBox; if (e.NewValue != e.OldValue) { SetImageSource(ab, (ImageSource)e.NewValue); } }
private static void OnShapeTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AvatarBox ab = d as AvatarBox; if (e.NewValue != e.OldValue) { SetClip(ab, (ShapeType)e.NewValue); } }
private static void OnInnerMarginChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AvatarBox ab = d as AvatarBox; if (e.NewValue != e.OldValue) { SetInnerMargin(ab, (double)e.NewValue); } }
private static void SetClip(AvatarBox avatarBox, ShapeType newValue) { Point center = new Point(); center.X = avatarBox.ActualWidth > 0 ? avatarBox.ActualWidth / 2 : 0; center.Y = avatarBox.ActualHeight > 0 ? avatarBox.ActualHeight / 2 : 0; avatarBox.Clip = new EllipseGeometry() { Center = center, RadiusX = center.X, RadiusY = center.Y }; if (avatarBox.innerBG != null) { avatarBox.innerBG.CornerRadius = new CornerRadius(double.MaxValue); } }