By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,454 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,454 IT Pros & Developers. It's quick & easy.

RE: WPF: Use MultiBinding to bind polyline point to a thumb

P: n/a
Hi George,

Thank you for posting!

This is a quick note to let you know that I am doing research on this issue
and will get back to you ASAP.

I appreciate your patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 3 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanks Chris for your wonderful reply!

Hi George,

As Chris has points out, the reason why the first point of the polyline is
not actually bound to the thumb is that when a dependency property of a
binding target is bound to a data source, the corresponding CLR property
won't be called when data binding retrieves data from data source to
binding target.

In your case, the Set property procedure of the FirstPoint property will
never be called when you drag the thumb.

The workaround that Chris provided is correct.
Also, any ideas how I could revise this to bind to any other point of the
polyline.

I suggest that you add a static field in the ArrowPolyline class for the
index of the bound point and add a method to set this value. Then you can
use this static field in the PropertyChangedCallback handler of the
FirstPointProperty dependency property (since we'll bind any point of the
polyline now, you may rename the FirstPointProperty to BoundPointProperty).
For example:

public class ArrowPolyline : ArrowLineBase
{
private static int boundPointIndex = -1;
public int BoundPointIndex
{
get { return boundPointIndex; }
}

public bool BindToPoint(int index, ref Point pt)
{
if (index >= 0 && index < Points.Count)
{
boundPointIndex = index;
pt = Points[index];
return true;
}
else
{
return false;
}
}

public static readonly DependencyProperty BoundPointProperty =
DependencyProperty.Register("FirstPoint", typeof(Point),
typeof(ArrowPolyline),
new FrameworkPropertyMetadata(new Point(0, 0),
FrameworkPropertyMetadataOptions.AffectsMeasure,
(DependencyObject sender,
DependencyPropertyChangedEventArgs e) =>
{
ArrowPolyline polyline = sender as
ArrowPolyline;
if (boundPointIndex >= 0 && boundPointIndex <
polyline.Points.Count)
{
polyline.Points[boundPointIndex] =
polyline.BoundPoint;
}
}));

public Point BoundPoint
{
set { SetValue(BoundPointProperty, value); }
get { return (Point)GetValue(BoundPointProperty); }
}
*
}

Add a TextBox on the Window1 and add the following code in the code of the
Window1:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ArrowPolyline ap = AddArrowPolyline();
Thumb thm = AddThumb();
BindPolylineToThumb(thm, ap);
}

// input the index of the point you want to bind in the TextBox and press
the Button
private void button1_Click(object sender, RoutedEventArgs e)
{
Point pt = new Point ();
if (ap.BindToPoint(Convert.ToInt32(this.textBox1.Text ), ref pt))
{
Canvas.SetLeft(this.myThumb, pt.X - this.myThumb.Width/2);
Canvas.SetTop(this.myThumb, pt.Y-this.myThumb.Height /2);
}
}

Run the application and input the index of the point you want to bind in
the TextBox and press the Button. You should see the thumb moves to the
location of the specified point and the point moves with the thumb when you
drag the thumb.

I will send the modified sample project to your email box. Please run it on
your machine to see if there's any problem.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.