public class InkPicture :InkCanvas
{
public static readonly DependencyProperty PBHeightProperty =
DependencyProperty.Register(
"PBHeight",
typeof(short),
typeof(InkPicture),
new FrameworkPropertyMetadata((short)400, new
PropertyChangedCallback(OnPBHeightChanged)));
public static readonly DependencyProperty PBWidthProperty =
DependencyProperty.Register(
"PBWidth",
typeof(short),
typeof(InkPicture),
new FrameworkPropertyMetadata((short)480, new
PropertyChangedCallback(OnPBWidthChanged)));
public static readonly RoutedEvent HeightChangedEvent =
EventManager.RegisterRoutedEvent(
"PBHeightChanged",
RoutingStrategy.Bubble,
typeof(RoutedPropertyChangedEventHandler<short>),
typeof(InkPicture));
public static readonly RoutedEvent WidthChangedEvent =
EventManager.RegisterRoutedEvent(
"WidthChanged",
RoutingStrategy.Bubble,
typeof(RoutedPropertyChangedEventHandler<short>),
typeof(InkPicture));
public InkPicture()
{
this.SetPropertylBinding("PBHeight",
InkPicture.HeightProperty);
this.SetPropertylBinding("PBWidth",
InkPicture.WidthProperty);
}
public short PBHeight
{
get
{
return (short)GetValue(PBHeightProperty);
}
set
{
this.SetValue(PBHeightProperty, value);
}
}
public short PBWidth
{
get
{
return (short)GetValue(PBWidthProperty);
}
set
{
SetValue(PBWidthProperty, value);
}
}
private static void OnPBHeightChanged(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
InkPicture control = obj as InkPicture;
RoutedPropertyChangedEventArgs<short> e = new
RoutedPropertyChangedEventArgs<short>(
(short)args.OldValue, (short)args.NewValue,
HeightChangedEvent);
MessageBox.Show("pbheight changed");
control.RaiseEvent(e);
}
private static void OnPBWidthChanged(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
InkPicture control = obj as InkPicture;
RoutedPropertyChangedEventArgs<short> e = new
RoutedPropertyChangedEventArgs<short>(
(short)args.OldValue, (short)args.NewValue,
WidthChangedEvent);
control.RaiseEvent(e);
}
private void SetPropertylBinding(string path,
DependencyProperty target)
{
Binding bind = new Binding();
bind.RelativeSource = new
RelativeSource(RelativeSourceMode.Self);
bind.Path = new PropertyPath(path);
bind.Mode = BindingMode.TwoWay;
bind.UpdateSourceTrigger =
UpdateSourceTrigger.PropertyChanged;
bind.ConverterCulture = new CultureInfo("en-US");
SetBinding(target, bind);
}
}
--
astw