简体   繁体   中英

“Link” items in a WPF TreeView

I have a WPF TreeView that represents an object graph in which some objects implicitely references each others.

For those, I'd like to be able to draw an arrow linking them when I select one of them:

在此处输入图片说明

I looked into the Adorners but I am not sure it's the correct way to go since I cannot find a way to get the graphical position of two items in the TreeView...

Any idea what I could do here?

first, you could get the relative item position with this:

var myItem = (UIElement)myTreeView.SelectedItem;
var pos1 = myItem.TranslatePoint(new Point(), myTreeView);
var pos2 = myAnyOtherItem.TranslatePoint(new Point(), myTreeView);

if you don't have access to the UIElement look for
"get container from data object (WPF TreeView)"
but this is a other question and I'm sure there is already a solution ^^

second, using an adorner is good idea
but I'm sure there are enough samples ^^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM