Hi,
[quoted text, click to view] "moondaddy" <moondaddy@noemail.noemail> wrote in message
news:OYzet6DMHHA.1872@TK2MSFTNGP04.phx.gbl...
> Thanks but that didnt seem to have any effect. One line didnt compile
> which I changed from:
> BndX1.Path = "CenterX";
> to
> BndX1.Path = new PropertyPath("CenterX");
Yeah, sorry for that, new to WPF. I still believe the path thing is
necessairly... Most SDK doc examples setup the path in the binding ctor:
Binding BndX1 = new Binding("CenterX");
BndX1.Source = shpX;
BindingOperations.SetBinding(ln, Line.X1Property, BndX1);
Though i doubt this will make any difference from what you already tried.
You did mention that it worked when binding in XAML, that would indicate
that there's nothing wrong with your shape class, so it would be good to see
how you got it working using XAML.
[quoted text, click to view] >
> I'm going to send Walter a cleaned up sample of this in a response to his
> post below if you want to take a look at it.
If you want you may mail me that sample too.
Greetings
[quoted text, click to view] >
> Thanks again.
>
>
> "Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message
> news:ckvlh.264408$mo5.5439581@phobos.telenet-ops.be...
>> Hi,
>>
>> "moondaddy" <moondaddy@noemail.noemail> wrote in message
>> news:u2oc1cyKHHA.4912@TK2MSFTNGP02.phx.gbl...
>>> I'm trying to databind a dependency property in a custom control
>>> (CenterX) to the Line.X1Property property of line. If I can correctly
>>> do this (and the same for the 'Y' props) then when I drag my custom
>>> control the line should follow it (stay connected) I know the
>>> dependency props in my custom control work OK because all works OK when
>>> I do this in xaml, but when I try to set it up at run time via c# in the
>>> codebehind, the line does not stay connected to the custom control.
>>>
>>> Here's the code that creates 2 instances of the custom control (myShape)
>>> and a line. When this code runs it creates all 3 objects and correctly
>>> connects the line to each custom control. but when I drag the controls
>>> the line doesn't stay connected.
>>>
>>>
>>> //CREATE THE 1ST CONTROL
>>> myShape shpX = new myShape();
>>> shpX.SetMyParent(canvas1);
>>> shpX.Width = 150;
>>> shpX.Height = 50;
>>> shpX.InitializeBordersAsRectangle();
>>> shpX.Name = "shpX";
>>>
>>> shpX.PreviewMouseDown += new
>>> MouseButtonEventHandler(myElement_PreviewMouseDown);
>>> shpX.PreviewMouseMove += new
>>> MouseEventHandler(myElement_PreviewMouseMove);
>>> shpX.MouseLeftButtonUp += new MouseButtonEventHandler(MouseUpHandler);
>>>
>>> this.canvas1.Children.Add(shpX);
>>> Canvas.SetLeft(shpX, 100);
>>> Canvas.SetTop(shpX, 100);
>>>
>>> //CREATE THE 2ND CUSTOM CONTROL
>>> myShape shpX2 = new myShape();
>>> shpX2.SetMyParent(canvas1);
>>> shpX2.Width = 150;
>>> shpX2.Height = 50;
>>> shpX2.InitializeBordersAsRectangle();
>>> shpX2.Name = "shpX2";
>>>
>>> shpX2.PreviewMouseDown += new
>>> MouseButtonEventHandler(myElement_PreviewMouseDown);
>>> shpX2.PreviewMouseMove += new
>>> MouseEventHandler(myElement_PreviewMouseMove);
>>> shpX2.MouseLeftButtonUp += new MouseButtonEventHandler(MouseUpHandler);
>>>
>>> this.canvas1.Children.Add(shpX2);
>>> Canvas.SetLeft(shpX2, 300);
>>> Canvas.SetTop(shpX2, 300);
>>>
>>> //CREATE THE LINE
>>> Line ln = new Line();
>>> ln.Stroke = Brushes.Red;
>>> ln.StrokeThickness = 3;
>>>
>>> //DATA BIND ONE END OF LINE TO THE 1ST CONTROL
>>> Binding BndX1 = new Binding();
>>> BndX1.Mode = BindingMode.OneWay;
>>> BndX1.Source = shpX.CenterX;
>>> BindingOperations.SetBinding(ln, Line.X1Property, BndX1);
>>
>> Based on winforms experience i would try:
>>
>> Binding BndX1 = new Binding();
>> BndX1.Source = shpX;
>> BndX1.Path = "CenterX";
>> BindingOperations.SetBinding(ln, Line.X1Property, BndX1);
>>
>> HTH,
>> Greetings
>>
>>>
>>> Binding BndY1 = new Binding();
>>> BndY1.Source = shpX.CenterY;
>>> BindingOperations.SetBinding(ln, Line.Y1Property, BndY1);
>>>
>>> //DATA BIND THE 2ND END OF THE LINE TO THE 2ND CONTROL
>>> // I USED 'SETBINDING' IN A DIFFERENT WAY HERE TO SEE IF IT MADE A
>>> DIFFERENCE.
>>> // BOTH WAYS WORKED THE SAME.
>>> Binding BndX2 = new Binding();
>>> BndX2.Source = shpX2.CenterX;
>>> ln.SetBinding(Line.X2Property, BndX2);
>>>
>>> Binding BndY2 = new Binding();
>>> BndY2.Source = shpX2.CenterY;
>>> ln.SetBinding(Line.Y2Property, BndY2);
>>>
>>>
>>> Can anyone please help help me get this running?
>>>
>>> Thanks!
>>>
>>>
>>>
>>>
>>> --
>>> moondaddy@noemail.noemail
>>>
>>
>>
>
>