|
| | |||||||
| Tablet PC Developers Show off your work while discussing with others how to create ink enabled applications. |
| | LinkBack | Thread Tools |
| |||
| Hi, I inherited new class from InkCanvas, and define two dependency properties PBWidth PBHeight which is bind respectively to the Width, and Height properties. When add this new class to a window, and change the PBWidth, or PBHeight property in the XAML file, the control's size can not be changed, this is not what I expected. But in runtime, change the PBHeight or PBWidth, the control's height or width can be changed. What's wrong with it? I post the simplified code of the class here, please help me to see what's wrong with it, thank you very much! 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); } } |
| Bookmarks |
| Tags |
| dependency property, design time, inkcanvas |
| Thread Tools | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Design pattern – Inversion of control and Dependency injection | TPC | General Questions | 0 | 09-15-2008 03:10 AM |
| Design pattern – Inversion of control and Dependency injection | TPC | General Questions | 0 | 09-13-2008 06:41 PM |
| Design pattern – Inversion of control and Dependency injection | TPC | General Questions | 0 | 09-13-2008 10:40 AM |
| Design pattern – Inversion of control and Dependency injection | TPC | General Questions | 0 | 09-13-2008 08:30 AM |
| Difference between Windows Time Service and Internet Time in Date & Time Properties | Saucer Man | Windows XP | 0 | 02-14-2008 06:00 AM |
| New To Technology Questions? | Do You Need Help with Your Computer or Device? | Do You Need Help with this site? |