Reputation: 269
I am developing interactive chart library...and application, which use it.
In application, I have a ListView
with Points
of the CurrentItem
.
public Point CurrentPoint
{
get { return myCurrentPoint; }
set
{
myCurrentPoint = value;
base.OnPropertyChanged("CurrentPoint");
}
}
At the same panel, I have two textboxes for editing point's coordinates:
<TextBox Text="{Binding CurrentPoint.X, Mode=TwoWay}"
Grid.Column="1" Grid.Row="0" Width="80" Margin="5"/>
My big problem is, that Point
is a structure...so it's passing by value.
If I change X
coordinate in textbox...it doesn't change databind Point
.
How can I solve this problem?
Should I write my own Point
class, and Line
class too, because of her Points
are PointCollection
of Point
?
If it's needed, I can post more code :)
Thanks.
Upvotes: 0
Views: 995
Reputation: 36785
Why not create a combined control that changes the Point instead of the x-and y-component of the Point
. Then you can bind to your Point
-property and binding will work as expected. Furthermore, you have probably a nicer UI.
You can create a UserControl
, add two text-boxes and add a DependencyProperty-Point
to this control. Everytime the contents of one of the textboxes changes, set the Point
-property to its new value.
public class PointInputBox : UserControl{
public static readonly DependencyProperty PointProperty =
DependencyProperty.Register("Point", typeof(Point), typeof(PointInputBox), new FrameworkPropertyMetadata(new Point(0,0),FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public Point Point {
get { return (Point)GetValue(PointProperty); }
set { SetValue(PointProperty, value); }
}
// Add here event handlers for changes of your input boxes and set
// the Point-value accordingly
Upvotes: 1