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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
namespace WpfApplication4
{
public class MyButton : Button
{
static MyButton()
{
//DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
}
public MyButton()
{ }
public int Row
{
get { return (int)GetValue(RowProperty); }
set { SetValue(RowProperty, value); }
}
// Using a DependencyProperty as the backing store for Row. This enables animation, styling, binding, etc...
public static readonly DependencyProperty RowProperty =
DependencyProperty.Register("Row",
typeof(int), typeof(MyButton),
new FrameworkPropertyMetadata (0,
FrameworkPropertyMetadataOptions.AffectsRender ,OnRowChanged ));
private static void OnRowChanged(DependencyObject d,DependencyPropertyChangedEventArgs args)
{
MyButton ct = d as MyButton;
int row = (int)args.NewValue;
ContentPresenter cp = ct.VisualParent as ContentPresenter;
if (cp != null)
Grid.SetRow(cp, row);
else //comportement normal s'il est ajoute directement à grid
Grid.SetRow(ct, row);
}
public int Col
{
get { return (int)GetValue(ColProperty); }
set { SetValue(ColProperty, value); }
}
// Using a DependencyProperty as the backing store for Col. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ColProperty =
DependencyProperty.Register("Col", typeof(int),
typeof(MyButton),
new FrameworkPropertyMetadata(0,
FrameworkPropertyMetadataOptions.AffectsRender, OnColChanged));
private static void OnColChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
MyButton ct = d as MyButton;
int col = (int)args.NewValue;
ContentPresenter cp = ct.VisualParent as ContentPresenter;
if (cp != null)
Grid.SetColumn(cp, col);
else
Grid.SetColumn(ct, col);
}
}
} |
Partager