VB.NET WPF 2 TreeViews相同的ItemsSource

时间:2015-06-24 12:31:08

标签: .net wpf vb.net xaml treeview

目前我正在尝试向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

1 个答案:

答案 0 :(得分:1)

原因是# -*- coding: utf-8 -*- def long_running(): import time time.sleep(10) # does not show "Python ... stopped working ..." #for _ in range(20): # time.sleep(0.5) # wx.Yield() if __name__ == '__main__': import wx app = wx.App() bitmap = wx.EmptyBitmap(300, 150, 127) splash = wx.SplashScreen(bitmap, wx.SPLASH_TIMEOUT, 20000, None) # Begin loading the application. long_running() # Application loaded. #Destroy the splash screen. splash.Hide() splash.Destroy() app.MainLoop() 已经是TreeViewItem使用的可视对象。如果您使用任何其他自定义对象并将其格式化为要在TreeView的{​​{1}}中显示的内容,则可以使用相同的对象。

但你不能用ItemTemplate s。

来做到这一点