Using the following code, I am able to change the "Left" and "Top" values in the PropertyGrid and see the CanvasItem being moved in the canvas.
<Window x:Class="WpfApplication24.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WpfApplication24"
Title="MainWindow" >
<Grid>
<StackPanel>
<xctk:PropertyGrid x:Name="_propertyGrid" Height="400"/>
<Canvas >
<local:CanvasItem x:Name="_item" Content="DATA" Left="33" Top="50"/>
</Canvas>
</StackPanel>
</Grid>
</Window>
namespace WpfApplication24
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
_propertyGrid.SelectedObject = _item;
}
}
public class CanvasItem : ContentControl
{
#region LeftProperty
public static readonly DependencyProperty LeftProperty = DependencyProperty.Register( "Left", typeof( Double ), typeof( CanvasItem ), new UIPropertyMetadata( 0d, OnLeftChanged ) );
public Double Left
{
get { return (Double)GetValue(LeftProperty); }
set
{
SetValue(LeftProperty, value);
}
}
private static void OnLeftChanged( DependencyObject o, DependencyPropertyChangedEventArgs e )
{
CanvasItem item = o as CanvasItem;
if( item != null )
{
Canvas.SetLeft( item, ( Double )e.NewValue );
}
}
#endregion
#region TopProperty
public static readonly DependencyProperty TopProperty = DependencyProperty.Register( "Top", typeof( Double ), typeof( CanvasItem ), new UIPropertyMetadata( 0d, OnTopChanged ) );
public Double Top
{
get
{
return ( Double )GetValue( TopProperty );
}
set
{
SetValue( TopProperty, value );
}
}
private static void OnTopChanged( DependencyObject o, DependencyPropertyChangedEventArgs e )
{
CanvasItem item = o as CanvasItem;
if( item != null )
{
Canvas.SetTop( item, ( Double )e.NewValue );
}
}
#endregion
}
}