├── .gitattributes ├── .gitignore ├── Demo ├── App.config ├── App.xaml ├── App.xaml.cs ├── Demo.csproj ├── MainViewModel.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── LICENSE ├── README.md ├── TreeListView.sln ├── TreeListView ├── Converter │ └── TreeViewMarginConverter.cs ├── Extensions │ ├── FrameworkElementExtensions.cs │ ├── TreeViewItemExtensions.cs │ └── WpfExtensions.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ └── TreeListView.xaml ├── TreeListView.cs ├── TreeListView.csproj └── TreeListViewItem.cs └── appveyor.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | 254 | # ========================= 255 | # Operating System Files 256 | # ========================= 257 | 258 | # OSX 259 | # ========================= 260 | 261 | .DS_Store 262 | .AppleDouble 263 | .LSOverride 264 | 265 | # Thumbnails 266 | ._* 267 | 268 | # Files that might appear in the root of a volume 269 | .DocumentRevisions-V100 270 | .fseventsd 271 | .Spotlight-V100 272 | .TemporaryItems 273 | .Trashes 274 | .VolumeIcon.icns 275 | 276 | # Directories potentially created on remote AFP share 277 | .AppleDB 278 | .AppleDesktop 279 | Network Trash Folder 280 | Temporary Items 281 | .apdisk 282 | 283 | # Windows 284 | # ========================= 285 | 286 | # Windows image file caches 287 | Thumbs.db 288 | ehthumbs.db 289 | 290 | # Folder config file 291 | Desktop.ini 292 | 293 | # Recycle Bin used on file shares 294 | $RECYCLE.BIN/ 295 | 296 | # Windows Installer files 297 | *.cab 298 | *.msi 299 | *.msm 300 | *.msp 301 | 302 | # Windows shortcuts 303 | *.lnk 304 | -------------------------------------------------------------------------------- /Demo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Demo/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Demo/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Demo 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Demo/Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | $(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets 4 | net45 5 | WinExe 6 | 7 | 8 | 9 | 10 | full 11 | true 12 | 13 | 14 | 15 | 16 | 17 | Designer 18 | MSBuild:UpdateDesignTimeXaml 19 | 20 | 21 | 22 | 23 | Designer 24 | MSBuild:UpdateDesignTimeXaml 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace Demo 5 | { 6 | public class MainViewModel 7 | { 8 | public MainViewModel() 9 | { 10 | Collection = new ObservableCollection 11 | { 12 | new TestData 13 | { 14 | Name = "Être", 15 | Category = TestCategory.None, 16 | Description = "If you be there", 17 | GarconLevel = 18, 18 | Children = new List 19 | { 20 | new TestData 21 | { 22 | Name = "suis", 23 | Category = TestCategory.Je, 24 | GarconLevel = 13, 25 | Description = "If I am there" 26 | }, 27 | new TestData 28 | { 29 | Name = "es", 30 | Category = TestCategory.Tu, 31 | GarconLevel = 13, 32 | Description = "If you are there" 33 | }, 34 | new TestData 35 | { 36 | Name = "Multiple Options", 37 | Category = TestCategory.None, 38 | Description = "", 39 | GarconLevel = -1, 40 | Children = new List 41 | { 42 | new TestData 43 | { 44 | Name = "est", 45 | Category = TestCategory.Il, 46 | GarconLevel = 198, 47 | Description = "If he is there" 48 | }, 49 | new TestData 50 | { 51 | Name = "est", 52 | Category = TestCategory.Elle, 53 | GarconLevel = 198, 54 | Description = "If she is there" 55 | }, 56 | new TestData 57 | { 58 | Name = "est", 59 | Category = TestCategory.On, 60 | GarconLevel = 198, 61 | Description = "If he it there" 62 | } 63 | } 64 | } 65 | } 66 | } 67 | }; 68 | 69 | for (int i = 0; i < 1000; i++) 70 | { 71 | Collection.Add(new TestData {Name = "Virtualizing Test"}); 72 | } 73 | } 74 | 75 | public ObservableCollection Collection { get; } 76 | } 77 | 78 | public class TestData 79 | { 80 | public string Name { get; set; } 81 | public TestCategory Category { get; set; } 82 | public string Description { get; set; } 83 | public int GarconLevel { get; set; } 84 | public List Children { get; set; } 85 | } 86 | 87 | public enum TestCategory 88 | { 89 | None, 90 | Je, 91 | Tu, 92 | Il, 93 | Elle, 94 | On, 95 | Nous, 96 | Vous, 97 | IlsElles 98 | } 99 | } -------------------------------------------------------------------------------- /Demo/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Demo/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace Demo 17 | { 18 | /// 19 | /// Interaction logic for MainWindow.xaml 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | [assembly: ThemeInfo( 10 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 11 | //(used if a resource is not found in the page, 12 | // or application resource dictionaries) 13 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 14 | //(used if a resource is not found in the page, 15 | // app, or any theme specific resource dictionaries) 16 | )] 17 | -------------------------------------------------------------------------------- /Demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Vincent 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MetroTreeListView 2 | A TreeView with columns which behaves a little bit like a ListView. The style is based on the [MahApps.Metro](https://github.com/MahApps/MahApps.Metro) library. 3 | 4 | ![TreeListView](http://i.imgur.com/b7QqbAo.png) 5 | -------------------------------------------------------------------------------- /TreeListView.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.10 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TreeListView", "TreeListView\TreeListView.csproj", "{BE9E6BCE-C30F-47EF-AEE9-37F502DE4F5C}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "Demo\Demo.csproj", "{B8644C4D-F563-4782-90F3-F737942A4B1D}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BE9E6BCE-C30F-47EF-AEE9-37F502DE4F5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {BE9E6BCE-C30F-47EF-AEE9-37F502DE4F5C}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {BE9E6BCE-C30F-47EF-AEE9-37F502DE4F5C}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {BE9E6BCE-C30F-47EF-AEE9-37F502DE4F5C}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {B8644C4D-F563-4782-90F3-F737942A4B1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B8644C4D-F563-4782-90F3-F737942A4B1D}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B8644C4D-F563-4782-90F3-F737942A4B1D}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B8644C4D-F563-4782-90F3-F737942A4B1D}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {96CDF8CB-47E4-4612-B278-C146CB1753BC} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TreeListView/Converter/TreeViewMarginConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Data; 6 | using TreeListView.Extensions; 7 | 8 | namespace TreeListView.Converter 9 | { 10 | //Taken from https://github.com/MahApps/MahApps.Metro/blob/2fed9c9d91695903d0548fc4dffb7f1af3a1a917/src/MahApps.Metro/MahApps.Metro.Shared/Converters/TreeViewMarginConverter.cs 11 | internal class TreeViewMarginConverter : IValueConverter 12 | { 13 | public double Length { get; set; } 14 | 15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (!(value is TreeViewItem item)) 18 | return new Thickness(0); 19 | 20 | return new Thickness(Length * item.GetDepth(), 0, 0, 0); 21 | } 22 | 23 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | return DependencyProperty.UnsetValue; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /TreeListView/Extensions/FrameworkElementExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace TreeListView.Extensions 4 | { 5 | internal static class FrameworkElementExtensions 6 | { 7 | public static readonly DependencyProperty SuppressBringIntoViewProperty = DependencyProperty.RegisterAttached( 8 | "SuppressBringIntoView", typeof (bool), typeof (FrameworkElementExtensions), 9 | new PropertyMetadata(default(bool), PropertyChangedCallback)); 10 | 11 | private static void PropertyChangedCallback(DependencyObject dependencyObject, 12 | DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 13 | { 14 | var frameworkElement = (FrameworkElement) dependencyObject; 15 | frameworkElement.RequestBringIntoView -= FrameworkElementOnRequestBringIntoView; //prevent memory leak 16 | 17 | if ((bool) dependencyPropertyChangedEventArgs.NewValue) 18 | frameworkElement.RequestBringIntoView += FrameworkElementOnRequestBringIntoView; 19 | } 20 | 21 | private static void FrameworkElementOnRequestBringIntoView(object sender, 22 | RequestBringIntoViewEventArgs requestBringIntoViewEventArgs) 23 | { 24 | requestBringIntoViewEventArgs.Handled = true; 25 | } 26 | 27 | public static void SetSuppressBringIntoView(DependencyObject element, bool value) 28 | { 29 | element.SetValue(SuppressBringIntoViewProperty, value); 30 | } 31 | 32 | public static bool GetSuppressBringIntoView(DependencyObject element) 33 | { 34 | return (bool) element.GetValue(SuppressBringIntoViewProperty); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TreeListView/Extensions/TreeViewItemExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | using System.Windows.Media; 3 | 4 | namespace TreeListView.Extensions 5 | { 6 | internal static class TreeViewItemExtensions 7 | { 8 | public static int GetDepth(this TreeViewItem item) 9 | { 10 | TreeViewItem parent; 11 | while ((parent = GetParent(item)) != null) 12 | { 13 | return GetDepth(parent) + 1; 14 | } 15 | return 0; 16 | } 17 | 18 | private static TreeViewItem GetParent(TreeViewItem item) 19 | { 20 | var parent = item != null ? VisualTreeHelper.GetParent(item) : null; 21 | while (parent != null && !(parent is TreeViewItem || parent is TreeView)) 22 | { 23 | parent = VisualTreeHelper.GetParent(parent); 24 | } 25 | return parent as TreeViewItem; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /TreeListView/Extensions/WpfExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Media; 3 | using System.Windows.Media.Media3D; 4 | 5 | namespace TreeListView.Extensions 6 | { 7 | internal static class WpfExtensions 8 | { 9 | internal static T VisualUpwardSearch(DependencyObject source) where T : DependencyObject 10 | { 11 | var returnVal = source; 12 | 13 | while (returnVal != null && !(returnVal is T)) 14 | { 15 | DependencyObject tempReturnVal = null; 16 | if (returnVal is Visual || returnVal is Visual3D) 17 | { 18 | tempReturnVal = VisualTreeHelper.GetParent(returnVal); 19 | } 20 | if (tempReturnVal == null) 21 | { 22 | returnVal = LogicalTreeHelper.GetParent(returnVal); 23 | } 24 | else returnVal = tempReturnVal; 25 | } 26 | 27 | return returnVal as T; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /TreeListView/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo(ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 4 | //(used if a resource is not found in the page, 5 | // or application resource dictionaries) 6 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 7 | //(used if a resource is not found in the page, 8 | // app, or any theme specific resource dictionaries) 9 | )] -------------------------------------------------------------------------------- /TreeListView/Resources/TreeListView.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 75 | 76 | 77 | 175 | 196 | 207 | -------------------------------------------------------------------------------- /TreeListView/TreeListView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Data; 5 | using System.Windows.Input; 6 | using TreeListView.Extensions; 7 | 8 | namespace TreeListView 9 | { 10 | //Based on https://blogs.msdn.microsoft.com/atc_avalon_team/2006/03/01/treelistview-show-hierarchy-data-with-details-in-columns/ 11 | public class TreeListView : TreeView 12 | { 13 | public static readonly DependencyProperty ViewProperty = DependencyProperty.Register( 14 | "View", typeof (GridView), typeof (TreeListView), new PropertyMetadata(default(GridView), OnViewChanged)); 15 | 16 | public static readonly DependencyProperty SelectItemOnRightClickProperty = DependencyProperty.Register( 17 | "SelectItemOnRightClick", typeof (bool), typeof (TreeListView), new PropertyMetadata(true)); 18 | 19 | public static readonly DependencyProperty SelectedItemExProperty = DependencyProperty.Register( 20 | "SelectedItemEx", typeof (object), typeof (TreeListView), new PropertyMetadata(default(object))); 21 | 22 | public static readonly DependencyProperty ChildrenPropertyNameProperty = DependencyProperty.Register( 23 | "ChildrenPropertyName", typeof (string), typeof (TreeListView), 24 | new PropertyMetadata(default(string), OnChildrenPropertyNameChanged)); 25 | 26 | //Important: Disable property ItemTemplate 27 | public static readonly DependencyPropertyKey ReadOnlyItemTemplateProperty = DependencyProperty.RegisterReadOnly( 28 | "ItemTemplate", typeof (DataTemplate), typeof (TreeListView), new PropertyMetadata(default(DataTemplate))); 29 | 30 | public new static readonly DependencyProperty ItemTemplateProperty 31 | = ReadOnlyItemTemplateProperty.DependencyProperty; 32 | 33 | private GridViewColumn _currentGridViewColumn; 34 | private DataTemplate _oldDataTemplate; 35 | private BindingBase _oldDisplayMemberBindingBase; 36 | private GridViewColumnCollection _oldGridViewColumnCollection; 37 | private DataTemplateSelector _oldDataTemplateSelector; 38 | 39 | static TreeListView() 40 | { 41 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeListView), 42 | new FrameworkPropertyMetadata(typeof(TreeListView))); 43 | } 44 | 45 | public TreeListView() 46 | { 47 | SelectedItemChanged += OnSelectedItemChanged; 48 | } 49 | 50 | public new DataTemplate ItemTemplate 51 | { 52 | get => (DataTemplate) GetValue(ItemTemplateProperty); 53 | protected set => SetValue(ItemTemplateProperty, value); 54 | } 55 | 56 | public string ChildrenPropertyName 57 | { 58 | get => (string) GetValue(ChildrenPropertyNameProperty); 59 | set => SetValue(ChildrenPropertyNameProperty, value); 60 | } 61 | 62 | public GridView View 63 | { 64 | get => (GridView) GetValue(ViewProperty); 65 | set => SetValue(ViewProperty, value); 66 | } 67 | 68 | public object SelectedItemEx 69 | { 70 | get => GetValue(SelectedItemExProperty); 71 | set => SetValue(SelectedItemExProperty, value); 72 | } 73 | 74 | public bool SelectItemOnRightClick 75 | { 76 | get => (bool) GetValue(SelectItemOnRightClickProperty); 77 | set => SetValue(SelectItemOnRightClickProperty, value); 78 | } 79 | 80 | private static void OnViewChanged(DependencyObject dependencyObject, 81 | DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 82 | { 83 | var treeListView = (TreeListView) dependencyObject; 84 | var gridView = (GridView) dependencyPropertyChangedEventArgs.NewValue; 85 | treeListView.OnUpdateGridView(gridView?.Columns); 86 | } 87 | 88 | private void OnUpdateGridView(GridViewColumnCollection gridViewColumnCollection) 89 | { 90 | var isOldGridView = gridViewColumnCollection == _oldGridViewColumnCollection; 91 | 92 | if (!isOldGridView && _oldGridViewColumnCollection != null) 93 | { 94 | //unsubscribe old GridView 95 | _oldGridViewColumnCollection.CollectionChanged -= ColumnsOnCollectionChanged; 96 | ResetCurrentGridViewColumn(); 97 | _oldGridViewColumnCollection = null; 98 | } 99 | 100 | if (gridViewColumnCollection == null) 101 | return; 102 | 103 | if (!isOldGridView) 104 | gridViewColumnCollection.CollectionChanged += ColumnsOnCollectionChanged; 105 | 106 | if (gridViewColumnCollection.Count == 0) 107 | return; 108 | 109 | var firstColumn = gridViewColumnCollection[0]; 110 | ResetCurrentGridViewColumn(); 111 | _currentGridViewColumn = firstColumn; 112 | 113 | _oldDataTemplate = firstColumn.CellTemplate; 114 | _oldDataTemplateSelector = firstColumn.CellTemplateSelector; 115 | _oldDisplayMemberBindingBase = firstColumn.DisplayMemberBinding; 116 | 117 | var spFactory = new FrameworkElementFactory(typeof(ContentPresenter)); 118 | spFactory.SetBinding(ContentPresenter.ContentProperty, firstColumn.DisplayMemberBinding ?? new Binding(".")); 119 | if (firstColumn.CellTemplate != null) 120 | spFactory.SetValue(ContentPresenter.ContentTemplateProperty, firstColumn.CellTemplate); 121 | else if (firstColumn.CellTemplateSelector != null) 122 | spFactory.SetValue(ContentPresenter.ContentTemplateSelectorProperty, firstColumn.CellTemplateSelector); 123 | 124 | spFactory.SetBinding(MarginProperty, 125 | new Binding 126 | { 127 | RelativeSource = 128 | new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1), 129 | Converter = (IValueConverter)Application.Current.Resources["LengthConverter"] 130 | }); 131 | 132 | var dataTemplate = new DataTemplate {VisualTree = spFactory}; 133 | firstColumn.DisplayMemberBinding = null; 134 | firstColumn.CellTemplateSelector = null; 135 | firstColumn.CellTemplate = dataTemplate; 136 | 137 | _oldGridViewColumnCollection = gridViewColumnCollection; 138 | } 139 | 140 | private void ResetCurrentGridViewColumn() 141 | { 142 | if (_currentGridViewColumn == null) 143 | return; 144 | 145 | _currentGridViewColumn.CellTemplate = _oldDataTemplate; 146 | _currentGridViewColumn.DisplayMemberBinding = _oldDisplayMemberBindingBase; 147 | _currentGridViewColumn.CellTemplateSelector = _oldDataTemplateSelector; 148 | 149 | _oldDataTemplate = null; 150 | _oldDisplayMemberBindingBase = null; 151 | _oldDataTemplateSelector = null; 152 | } 153 | 154 | private void ColumnsOnCollectionChanged(object sender, 155 | NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) 156 | { 157 | OnUpdateGridView((GridViewColumnCollection) sender); 158 | } 159 | 160 | private void OnSelectedItemChanged(object sender, 161 | RoutedPropertyChangedEventArgs routedPropertyChangedEventArgs) 162 | { 163 | SelectedItemEx = routedPropertyChangedEventArgs.NewValue; 164 | } 165 | 166 | private static void OnChildrenPropertyNameChanged(DependencyObject dependencyObject, 167 | DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 168 | { 169 | var treeListView = (TreeListView) dependencyObject; 170 | var newValue = (string) dependencyPropertyChangedEventArgs.NewValue; 171 | treeListView.UpdateItemTemplate(new HierarchicalDataTemplate {ItemsSource = new Binding(newValue)}); 172 | } 173 | 174 | private void UpdateItemTemplate(DataTemplate dataTemplate) 175 | { 176 | base.ItemTemplate = dataTemplate; 177 | } 178 | 179 | protected override DependencyObject GetContainerForItemOverride() 180 | { 181 | return new TreeListViewItem(); 182 | } 183 | 184 | protected override bool IsItemItsOwnContainerOverride(object item) 185 | { 186 | return item is TreeListViewItem; 187 | } 188 | 189 | protected override void OnPreviewMouseRightButtonDown(MouseButtonEventArgs e) 190 | { 191 | base.OnPreviewMouseRightButtonDown(e); 192 | if (!SelectItemOnRightClick) 193 | return; 194 | 195 | var treeListViewItem = 196 | WpfExtensions.VisualUpwardSearch(e.OriginalSource as DependencyObject); 197 | if (treeListViewItem != null) 198 | { 199 | treeListViewItem.Focus(); 200 | treeListViewItem.IsSelected = true; 201 | e.Handled = true; 202 | } 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /TreeListView/TreeListView.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net45 4 | 5 | 6 | 7 | 8 | 9 | Designer 10 | MSBuild:UpdateDesignTimeXaml 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /TreeListView/TreeListViewItem.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace TreeListView 5 | { 6 | public class TreeListViewItem : TreeViewItem 7 | { 8 | static TreeListViewItem() 9 | { 10 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeListViewItem), 11 | new FrameworkPropertyMetadata(typeof(TreeListViewItem))); 12 | } 13 | 14 | protected override DependencyObject GetContainerForItemOverride() 15 | { 16 | return new TreeListViewItem(); 17 | } 18 | 19 | protected override bool IsItemItsOwnContainerOverride(object item) 20 | { 21 | return item is TreeListViewItem; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '1.0.{build}' 2 | image: Visual Studio 2017 3 | branches: 4 | only: 5 | - master 6 | dotnet_csproj: 7 | patch: true 8 | file: '**\*.csproj' 9 | version: '{version}' 10 | package_version: '{version}' 11 | assembly_version: '{version}' 12 | file_version: '{version}' 13 | informational_version: '{version}-$(APPVEYOR_REPO_BRANCH)+$(APPVEYOR_REPO_COMMIT)' 14 | init: 15 | # Good practise, because Windows line endings are different from Unix/Linux ones 16 | - cmd: git config --global core.autocrlf true 17 | install: 18 | # Install repo specific stuff here 19 | before_build: 20 | # Display .NET Core version 21 | - cmd: dotnet --version 22 | # Display minimal restore text 23 | - cmd: dotnet restore ./TreeListView/TreeListView.csproj --verbosity m 24 | build_script: 25 | # output will be in ./src/bin/debug/netcoreapp1.1/publish 26 | - cmd: dotnet pack ./TreeListView/TreeListView.csproj -c Release 27 | after_build: 28 | # For once the build has completed 29 | artifacts: 30 | - path: '\TreeListView\bin\Release\*.nupkg' 31 | name: NuGet Package 32 | type: NuGetPackage 33 | clone_depth: 1 34 | on_finish : 35 | # any cleanup in here 36 | deploy: off --------------------------------------------------------------------------------