用一条线连接 2 个 ScatterViewItem?
我使用以下代码连接两个 ScatterViewItems。不幸的是,这不起作用,因为 center 属性不是单一值。但我无法从 CenterProperty 中读出值 x 和 y:
Line l = new Line();
l.Stroke = Brushes.Green;
l.StrokeThickness = 10;
Binding x1 = new Binding(); x1.Path = new PropertyPath(ScatterViewItem.CenterProperty);
x1.Converter = new MyConverter();
x1.ConverterParameter = root;
Binding y1 = new Binding(); y1.Path = new PropertyPath(ScatterViewItem.CenterProperty);
y1.Converter = new MyConverter();
y1.ConverterParameter = root;
Binding x2 = new Binding(); x2.Path = new PropertyPath(ScatterViewItem.CenterProperty);
x2.Converter = new MyConverter();
x2.ConverterParameter = level1;
Binding y2 = new Binding(); y2.Path = new PropertyPath(ScatterViewItem.CenterProperty);
y2.Converter = new MyConverter();
y2.ConverterParameter = level1;
x1.Source = y1.Source = root;
x2.Source = y2.Source = level1;
l.SetBinding(Line.X1Property, x1);
l.SetBinding(Line.Y1Property, y1);
l.SetBinding(Line.X2Property, x2);
l.SetBinding(Line.Y2Property, y2);
Dependencies.Children.Add(l);
l.Tag = new Call(focus, file);
Contacts.AddPreviewContactDownHandler(l, OnLineDown);
SizeChangedEventHandler act = (Object s, SizeChangedEventArgs args) =>
{
BindingOperations.GetBindingExpressionBase(l, Line.X1Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.Y1Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.X2Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.Y2Property).UpdateTarget();
};
root.SizeChanged += act;
level1.SizeChanged += act;
I use the following code to connect two ScatterViewItems. Unfortunately this does not work because the center property isn't asingle value. But I can't read out values x and y from the CenterProperty:
Line l = new Line();
l.Stroke = Brushes.Green;
l.StrokeThickness = 10;
Binding x1 = new Binding(); x1.Path = new PropertyPath(ScatterViewItem.CenterProperty);
x1.Converter = new MyConverter();
x1.ConverterParameter = root;
Binding y1 = new Binding(); y1.Path = new PropertyPath(ScatterViewItem.CenterProperty);
y1.Converter = new MyConverter();
y1.ConverterParameter = root;
Binding x2 = new Binding(); x2.Path = new PropertyPath(ScatterViewItem.CenterProperty);
x2.Converter = new MyConverter();
x2.ConverterParameter = level1;
Binding y2 = new Binding(); y2.Path = new PropertyPath(ScatterViewItem.CenterProperty);
y2.Converter = new MyConverter();
y2.ConverterParameter = level1;
x1.Source = y1.Source = root;
x2.Source = y2.Source = level1;
l.SetBinding(Line.X1Property, x1);
l.SetBinding(Line.Y1Property, y1);
l.SetBinding(Line.X2Property, x2);
l.SetBinding(Line.Y2Property, y2);
Dependencies.Children.Add(l);
l.Tag = new Call(focus, file);
Contacts.AddPreviewContactDownHandler(l, OnLineDown);
SizeChangedEventHandler act = (Object s, SizeChangedEventArgs args) =>
{
BindingOperations.GetBindingExpressionBase(l, Line.X1Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.Y1Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.X2Property).UpdateTarget();
BindingOperations.GetBindingExpressionBase(l, Line.Y2Property).UpdateTarget();
};
root.SizeChanged += act;
level1.SizeChanged += act;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在使用 Sebastian 在 Microsoft Surface 开发论坛中提出的以下解决方案:
XAML:
代码隐藏:
然后,如果您想在两个
ScatterViewItem
之间创建一条线,只需执行以下操作:I'm now using the followng solution, proposed in the Microsoft Surface Development forum by Sebastian:
XAML:
Code-behind:
Then if you want to create a line between two
ScatterViewItem
s, simply do this: