Hallo Liebe Gemeinde,
ich habe ein kleines Problem mit meinem Treeview control. undzwar möchte ich das Image bei einem Expandierten Node ändern. Leider funktioniort das nicht. Bzw. schon nach einem Refresh, nur sind dann alle Nodes collapsed.
Anbei mein XAML Code.
Spoiler anzeigen
und hier mein VB.Net Code.
Spoiler anzeigen
Was mache ich falsch?
Gruß
ich habe ein kleines Problem mit meinem Treeview control. undzwar möchte ich das Image bei einem Expandierten Node ändern. Leider funktioniort das nicht. Bzw. schon nach einem Refresh, nur sind dann alle Nodes collapsed.
Anbei mein XAML Code.
XML-Quellcode
- <Page
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:SWPDM_EnterPrise_Functions_001"
- xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="Folder_Selection"
- mc:Ignorable="d"
- d:DesignHeight="450" d:DesignWidth="800">
- <Page.Resources>
- <ResourceDictionary>
- <ResourceDictionary.MergedDictionaries>
- <ResourceDictionary Source="GOK_Style_Ressource.xaml"/>
- </ResourceDictionary.MergedDictionaries>
- </ResourceDictionary>
- </Page.Resources>
- <Grid>
- <DockPanel Background="White">
- <DockPanel DockPanel.Dock="Top" Height="42" VerticalAlignment="Top" >
- <Border x:Name="Border_01" DockPanel.Dock="Bottom" Background="#FF0162A6" Height="2" Margin="0" VerticalAlignment="Bottom"/>
- <TextBox x:Name="TXT_User" Text="User" Width="120" Margin="5,5,0,5" HorizontalAlignment="Left" Style="{StaticResource FontStyle_002}"/>
- <TextBox x:Name="TXT_PW" Text="User PW" Width="150" Margin="5,5,0,5" HorizontalAlignment="Left" Style="{StaticResource FontStyle_002}"/>
- <Button x:Name="BTN_Refresh_Tabel" Height="30" Width="30" HorizontalAlignment="Left" Margin="5,5,5,5" Style="{StaticResource Button_001}">
- <Image x:Name="BTN_Refresh_Tabel_Image" Stretch="Uniform"/>
- </Button>
- </DockPanel>
- <DockPanel DockPanel.Dock="Bottom" Background="#FFFDFDFD">
- <DockPanel DockPanel.Dock="Left" Width="Auto" MinWidth="250">
- <TreeView x:Name="FolderTreeView" TreeViewItem.Expanded="TreeViewItem_Expanded">
- <TreeView.ItemTemplate>
- <HierarchicalDataTemplate DataType="{x:Type local:FolderTree}" ItemsSource="{Binding SubItems}">
- <StackPanel Orientation="Horizontal" Height="22">
- <CheckBox Focusable="False" IsChecked="{Binding Checked}" VerticalAlignment="Center"/>
- <Image Name="FolderImage" Width="18" Height="18" Margin="5,0,0,0" Source="{Binding Image}" Stretch="Uniform"/>
- <TextBlock Text="{Binding Folder}" Style="{StaticResource FontStyle_004}" Margin="5,0,10,0" VerticalAlignment="Center"/>
- </StackPanel>
- <HierarchicalDataTemplate.Triggers>
- <DataTrigger Binding="{Binding IsExpanded_hnd}" Value="True">
- <Setter Property="Image.Source" Value="{Binding OpenImage}" TargetName="FolderImage"/>
- </DataTrigger>
- </HierarchicalDataTemplate.Triggers>
- </HierarchicalDataTemplate>
- </TreeView.ItemTemplate>
- </TreeView>
- </DockPanel>
- <DockPanel DockPanel.Dock="Right">
- <Grid>
- <DataGrid x:Name="DGR_001" Style="{StaticResource DataGridStyle_001}" Grid.Column="0" VirtualizingStackPanel.IsVirtualizing="False" Margin="0,0,1,0" ToolTip="Liste aller Sitzungen" CanUserAddRows="False" CanUserReorderColumns="False"/>
- </Grid>
- </DockPanel>
- </DockPanel>
- </DockPanel>
- </Grid>
- </Page>
und hier mein VB.Net Code.
VB.NET-Quellcode
- Option Strict On
- Imports System.Windows.Forms
- Imports System.Drawing
- Imports EdmLib
- Imports System.Windows
- Imports System.Windows.Input
- Public Class Folder_Selection
- Dim Folder_hnd As String = ""
- Dim VaultConn As IEdmVault5
- Dim SWPDM_MainInstance As Main_Instance = New Main_Instance
- Private GOKMF_Main_Instance As New GOK_Main_Functions.Main_Instance
- Private GOKMF_Image_Functions As New GOK_Main_Functions.GOK_Image_Functions(GOKMF_Main_Instance)
- Dim Get_Files As Boolean = False
- Dim FullFolderTree As FolderTree
- Public Sub New(ByVal PDM_Server As String, Optional ByVal GetFiles As Boolean = False)
- InitializeComponent()
- Select Case PDM_Server
- Case "GOK_SW_PDM"
- Folder_hnd = "C:\SW_PDM\"
- Case "GOK_TEST_PDM"
- Folder_hnd = "C:\TEST_PDM\"
- End Select
- SWPDM_MainInstance.GetNewVaultConnection(PDM_Server)
- Me.TXT_User.Text = SWPDM_MainInstance.GetCurrentUserName
- Get_Files = GetFiles
- FullFolderTree = GetFolderTree(Folder_hnd)
- Me.FolderTreeView.Items.Add(FullFolderTree)
- Me.BTN_Refresh_Tabel_Image.Source = GOKMF_Image_Functions.ConvertImageToImagesource(DirectCast(My.Resources.ResourceManager.GetObject("Reload"), Image))
- End Sub
- Private Sub FolderTreeView_SelectedItemChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Object)) Handles FolderTreeView.SelectedItemChanged
- Dim TempFolderTree As FolderTree = DirectCast(Me.FolderTreeView.SelectedItem, FolderTree)
- End Sub
- Public Function GetFolderTree(ByVal Main_Folder As String, Optional ByVal PDMImage As Boolean = True) As FolderTree
- Dim Returning_FolderTree As FolderTree = New FolderTree
- Dim Temp_DirectoryInfo As IO.DirectoryInfo = New IO.DirectoryInfo(Main_Folder)
- If PDMImage Then
- Returning_FolderTree.Folder = Main_Folder
- Returning_FolderTree.FullName = Temp_DirectoryInfo.FullName
- Returning_FolderTree.Checked = False
- Returning_FolderTree.Image = GOKMF_Image_Functions.ConvertImageToImagesource(DirectCast(My.Resources.ResourceManager.GetObject("SW_PDM_Icon"), Image))
- Returning_FolderTree.OpenImage = GOKMF_Image_Functions.ConvertImageToImagesource(DirectCast(My.Resources.ResourceManager.GetObject("SW_PDM_Icon"), Image))
- Else
- Returning_FolderTree.Folder = Temp_DirectoryInfo.Name
- Returning_FolderTree.FullName = Temp_DirectoryInfo.FullName
- Returning_FolderTree.Checked = False
- Returning_FolderTree.Image = GOKMF_Image_Functions.ConvertImageToImagesource(DirectCast(My.Resources.ResourceManager.GetObject("Folder_Closed"), Image))
- Returning_FolderTree.OpenImage = GOKMF_Image_Functions.ConvertImageToImagesource(DirectCast(My.Resources.ResourceManager.GetObject("Folder_Open"), Image))
- End If
- If Get_Files Then
- End If
- For Each SubFolder As IO.DirectoryInfo In Temp_DirectoryInfo.GetDirectories
- Returning_FolderTree.SubItems.Add(GetFolderTree(SubFolder.FullName, False))
- Next
- Return Returning_FolderTree
- End Function
- Public Sub TreeViewItem_Expanded(ByVal sender As Object, ByVal e As RoutedEventArgs)
- 'TODO: Ändern Bild wenn Treenode is expanded
- Dim Item As System.Windows.Controls.TreeViewItem = CType(e.OriginalSource, System.Windows.Controls.TreeViewItem)
- If Item.IsExpanded Then
- Dim temp As FolderTree = CType(Item.DataContext, FolderTree)
- temp.IsExpanded_hnd = Item.IsExpanded
- End If
- End Sub
- End Class
- Public Class FolderTree
- Public Property Image As System.Windows.Media.Imaging.BitmapImage
- Public Property OpenImage As System.Windows.Media.Imaging.BitmapImage
- Public Property Folder As String
- Public Property FullName As String
- Public Property IsExpanded_hnd As Boolean = False
- Public Property Checked As Boolean
- Public ReadOnly Property SubItems As List(Of FolderTree) = New List(Of FolderTree)()
- End Class
Was mache ich falsch?
Gruß