-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarginSetter.cs
35 lines (30 loc) · 1.12 KB
/
MarginSetter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Windows;
using System.Windows.Controls;
namespace KeywordDensity
{
public class MarginSetter
{
public static readonly DependencyProperty MarginProperty =
DependencyProperty.RegisterAttached("Margin",
typeof(Thickness),
typeof(MarginSetter),
new UIPropertyMetadata(new Thickness(), MarginChangedCallback));
public static Thickness GetMargin(DependencyObject obj) => (Thickness)obj.GetValue(MarginProperty);
public static void SetMargin(DependencyObject obj, Thickness value) => obj.SetValue(MarginProperty, value);
public static void MarginChangedCallback(object sender, DependencyPropertyChangedEventArgs e)
{
var panel = sender as Panel;
if (null != panel) panel.Loaded += panel_Loaded;
}
static void panel_Loaded(object sender, RoutedEventArgs e)
{
var panel = (Panel)sender;
foreach (var child in panel.Children)
{
var fe = child as FrameworkElement;
if (null != fe) fe.Margin = GetMargin(panel);
}
}
}
}