繁体   English   中英

VB.NET WPF 2 TreeViews相同的ItemsSource

[英]VB.NET WPF 2 TreeViews same ItemsSource

目前,我试图给TreeViews相同的TreeViewItem。

但它仅在其中之一中可见。

我不确定为什么...

MainWindow.xaml:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TreeView x:Name="t1" HorizontalAlignment="Left" Height="300" Margin="10,10,0,0" VerticalAlignment="Top" Width="238"/>
        <TreeView x:Name="t2" HorizontalAlignment="Left" Height="300" Margin="10,10,0,0" VerticalAlignment="Top" Width="239" Grid.Column="1"/>

    </Grid>
</Window>

MainWindow.xaml.vb:

Class MainWindow

    Private root As TreeViewItem

    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        root = New TreeViewItem()
        Dim obj1 As TreeViewItem = New TreeViewItem()
        Dim obj2 As TreeViewItem = New TreeViewItem()

        root.Header = "TEST"
        obj1.Header = "obj1"
        obj2.Header = "obj2"

        root.ItemsSource = {obj1, obj2}

        t1.ItemsSource = {root}
        t2.ItemsSource = {root}
    End Sub
End Class

原因是TreeViewItem已经是TreeView使用的可视对象。 如果您使用任何其他自定义对象并将其格式化为要在TreeViewItemTemplate中显示的对象,则可以使用相同的对象。

但是您不能使用TreeViewItem做到这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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