本文介绍了在ListBox(View)项之间绘制一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListBox / ListView,我试图绘制连接一些项目的行(可以跨越多列)。问题是,我想在DataTemplate中绘制线条,仅使用Bindings。 我的ListBoxItems有DataContext,
是一个拥有From和To项目的VM(这将是各种其他ListBoxItems的DataContext)。 我被困在哪里试图找出如何从标记绑定到ListBoxItem的坐标,因为我的上下文是所有底层对象,
并且我还没有找到一种方法将ListBox赋予绑定转换器。 / p>

理想情况下,我会有这样的事情:


< DataTemplate>


  &NBSP; < Line X1 =" {Binding From。[需要ItemContainerGenerator互动] .DesiredSize.X,Converter = ??}"


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; X2 =" {Binding To。[需要ItemContainerGenerator互动] .DesiredSize.X,Converter = ??} " ... />


< / DataTemplate>


到目前为止,我还没有找到办法做到这一点,因为我需要底层对象(具有From / To)和ItemcontainerGenerator for列表框或单独的ListBoxItems,我也无法想出一种方法,以
a单一绑定结束坐标值。

解决方案




嗨  RKPatrick,



目前,我找不到相关的相关信息。 
$


您可以上传OneDrive的最小可运行演示(包括您的测试材料并删除所有私人信息)。我们可以下载并调试(重现您的问题)。这有助于我们快速分析您的问题。 

   

以下链接可能对您有所帮助。



WPF TreeView with WinForms Style Fomat



$
最好的问候



Yong Lu



I have a ListBox/ListView, where I am trying to draw lines connecting some of the items (the can span multiple columns). The catch is that I'd like to draw the lines within a DataTemplate, using only Bindings.  my ListBoxItems have DataContext with a VM holding the From and To items (that would be the DataContext of the various other ListBoxItems).  Where I am stuck is trying to figure out how to bind to the ListBoxItem's coordinates from markup, since my context's are all the underlying objects, and I haven't found a way to give the ListBox to a binding converter.

Ideally, I'd have something like this:

<DataTemplate>

    <Line X1="{Binding From.[Need ItemContainerGenerator interaction here].DesiredSize.X, Converter=??}"

             X2="{Binding To.[Need ItemContainerGenerator interaction here].DesiredSize.X, Converter=??}"…/>

</DataTemplate>

So far, I haven't found a way to do this, since I need the underlying object (that has From/To) and either the ItemcontainerGenerator for the listbox or the individual ListBoxItems, and I also can't come up with a way to end up with a coordinate value with a single binding.

解决方案


Hi  RKPatrick,

Currently, I cannot find relevant information about this. 

You may can upload a minimal runnable demo to OneDrive(Including your test material and remove all private information). We can download it and debugging(reproduce your issue). This will help us quickly analyze your problem. 
   
The following links may helpful for you.

WPF TreeView with WinForms Style Fomat


Best regards

Yong Lu


这篇关于在ListBox(View)项之间绘制一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:14