Technology Questions

Go Back   Technology Questions > Hardware Questions > Mobile Computers > Tablet PC > Tablet PC Software > Tablet PC Developers

Tablet PC Developers Show off your work while discussing with others how to create ink enabled applications.

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 02-04-2009, 10:47 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
astw is on a distinguished road
Exclamation Custom dependency properties in InkCanvas can't work in design time

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);
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

 
Old 02-04-2009, 10:47 PM
Reply

Bookmarks

Tags
dependency property, design time, inkcanvas

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
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?

All times are GMT -8. The time now is 09:46 PM.


2003 - 2009 All Rights Reserved. Technology Questions

Search Engine Friendly URLs by vBSEO 3.3.0