Skip to content

Commit 59e3208

Browse files
Merge pull request #1 from susmitha-sundar/master
How to autofit item height based on content in wpf treeview
2 parents 6dd7e79 + c918734 commit 59e3208

39 files changed

+1609
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Syncfusion.UI.Xaml.TreeView;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Interactivity;
10+
11+
namespace AutoFitContentDemo
12+
{
13+
public class QueryNodeSizeEvent : Behavior<SfTreeView>
14+
{
15+
protected override void OnAttached()
16+
{
17+
this.AssociatedObject.QueryNodeSize += AssociatedObject_QueryNodeSize;
18+
base.OnAttached();
19+
}
20+
21+
private void AssociatedObject_QueryNodeSize(object sender, QueryNodeSizeEventArgs e)
22+
{
23+
if (e.Node.Level == 0)
24+
{
25+
//Returns specified item height for items.
26+
e.Height = 30;
27+
e.Handled = true;
28+
}
29+
else
30+
{
31+
// Returns item height based on the content loaded.
32+
e.Height = e.GetAutoFitNodeHeight();
33+
e.Handled = true;
34+
}
35+
}
36+
37+
protected override void OnDetaching()
38+
{
39+
this.AssociatedObject.QueryNodeSize -= AssociatedObject_QueryNodeSize;
40+
base.OnDetaching();
41+
}
42+
}
43+
}

AutoFitItemHeight/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
5+
</startup>
6+
</configuration>

AutoFitItemHeight/App.ico

4.19 KB
Binary file not shown.

AutoFitItemHeight/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application
2+
x:Class="AutoFitContentDemo.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="clr-namespace:AutoFitContentDemo"
6+
StartupUri="AutoFitContent.xaml">
7+
<Application.Resources />
8+
</Application>

AutoFitItemHeight/App.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.Licensing;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Configuration;
5+
using System.Data;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
10+
namespace AutoFitContentDemo
11+
{
12+
/// <summary>
13+
/// Interaction logic for App.xaml
14+
/// </summary>
15+
public partial class App : Application
16+
{
17+
public App()
18+
{
19+
SyncfusionLicenseProvider.RegisterLicense(DemoCommon.FindLicenseKey());
20+
}
21+
}
22+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Window
2+
x:Class="AutoFitContentDemo.AutoFitContent"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
7+
xmlns:local="clr-namespace:AutoFitContentDemo"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:skin="clr-namespace:Syncfusion.SfSkinManager;assembly=Syncfusion.SfSkinManager.WPF"
10+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
11+
Title="Auto Fit Content"
12+
Width="500"
13+
Height="600"
14+
Icon="App.ico"
15+
WindowStartupLocation="CenterScreen"
16+
mc:Ignorable="d">
17+
<Window.DataContext>
18+
<local:FileManagerViewModel />
19+
</Window.DataContext>
20+
<Grid>
21+
<syncfusion:SfTreeView
22+
x:Name="treeView"
23+
Margin="10"
24+
AutoExpandMode="RootNodes"
25+
BorderBrush="LightGray"
26+
BorderThickness="1"
27+
ChildPropertyName="SubFiles"
28+
ExpandActionTrigger="Node"
29+
FocusVisualStyle="{x:Null}"
30+
ItemsSource="{Binding ImageNodeInfo}">
31+
<syncfusion:SfTreeView.ItemTemplate>
32+
<DataTemplate>
33+
<Grid>
34+
<Grid.ColumnDefinitions>
35+
<ColumnDefinition Width="auto" />
36+
<ColumnDefinition Width="*" />
37+
</Grid.ColumnDefinitions>
38+
<Image
39+
Width="20"
40+
Height="20"
41+
Margin="0,5,0,5"
42+
VerticalAlignment="Top"
43+
Source="{Binding ImageIcon}" />
44+
<StackPanel
45+
Grid.Column="1"
46+
HorizontalAlignment="Stretch"
47+
VerticalAlignment="Center">
48+
<TextBlock
49+
Margin="5"
50+
VerticalAlignment="Center"
51+
FontSize="13"
52+
Foreground="#474747"
53+
Text="{Binding FileName}"
54+
TextWrapping="Wrap" />
55+
<TextBlock
56+
Margin="5,0,5,5"
57+
FontSize="12"
58+
Foreground="#474747"
59+
Opacity=" 0.75"
60+
Text="{Binding FileDescription}"
61+
TextWrapping="Wrap"
62+
Visibility="{Binding Visibility}" />
63+
</StackPanel>
64+
</Grid>
65+
</DataTemplate>
66+
</syncfusion:SfTreeView.ItemTemplate>
67+
<i:Interaction.Behaviors>
68+
<local:QueryNodeSizeEvent />
69+
</i:Interaction.Behaviors>
70+
</syncfusion:SfTreeView>
71+
</Grid>
72+
</Window>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 AutoFitContentDemo
17+
{
18+
/// <summary>
19+
/// Interaction logic for AutoFitContent.xaml
20+
/// </summary>
21+
public partial class AutoFitContent : Window
22+
{
23+
public AutoFitContent()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{32C01585-2D4A-4D70-A995-83DEAD479CF6}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>AutoFitContentDemo</RootNamespace>
11+
<AssemblyName>AutoFitContentDemo</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<WarningLevel>4</WarningLevel>
16+
<TargetFrameworkProfile />
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Resource Include="App.ico" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<Reference Include="Syncfusion.SampleLayout.WPF">
42+
<SpecificVersion>False</SpecificVersion>
43+
</Reference>
44+
<Reference Include="Syncfusion.SfTreeView.WPF" >
45+
<SpecificVersion>False</SpecificVersion>
46+
</Reference>
47+
<Reference Include="Syncfusion.SfSkinManager.WPF">
48+
<SpecificVersion>False</SpecificVersion>
49+
<Private>True</Private>
50+
</Reference>
51+
<Reference Include="Syncfusion.Themes.MaterialLight.WPF">
52+
<SpecificVersion>False</SpecificVersion>
53+
<Private>True</Private>
54+
</Reference>
55+
<Reference Include="System" />
56+
<Reference Include="System.Data" />
57+
<Reference Include="System.Windows.Interactivity">
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\Common\Data\Interactivity_Binaries\WPF\4.0\System.Windows.Interactivity.dll</HintPath>
60+
</Reference>
61+
<Reference Include="System.Xml" />
62+
<Reference Include="Microsoft.CSharp" />
63+
<Reference Include="System.Core" />
64+
<Reference Include="System.Xml.Linq" />
65+
<Reference Include="System.Data.DataSetExtensions" />
66+
<Reference Include="System.Net.Http" />
67+
<Reference Include="System.Xaml">
68+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
69+
</Reference>
70+
<Reference Include="WindowsBase" />
71+
<Reference Include="PresentationCore" />
72+
<Reference Include="PresentationFramework" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<ApplicationDefinition Include="App.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</ApplicationDefinition>
79+
<Page Include="AutoFitContent.xaml">
80+
<Generator>MSBuild:Compile</Generator>
81+
<SubType>Designer</SubType>
82+
</Page>
83+
<Compile Include="Actions\QueryNodeSizeEvent.cs" />
84+
<Compile Include="App.xaml.cs">
85+
<DependentUpon>App.xaml</DependentUpon>
86+
<SubType>Code</SubType>
87+
</Compile>
88+
<Compile Include="Model\FileManager.cs" />
89+
<Compile Include="ViewModel\FileManagerViewModel.cs" />
90+
<Compile Include="AutoFitContent.xaml.cs">
91+
<DependentUpon>AutoFitContent.xaml</DependentUpon>
92+
<SubType>Code</SubType>
93+
</Compile>
94+
</ItemGroup>
95+
<ItemGroup>
96+
<Compile Include="Properties\AssemblyInfo.cs">
97+
<SubType>Code</SubType>
98+
</Compile>
99+
<Compile Include="Properties\Resources.Designer.cs">
100+
<AutoGen>True</AutoGen>
101+
<DesignTime>True</DesignTime>
102+
<DependentUpon>Resources.resx</DependentUpon>
103+
</Compile>
104+
<Compile Include="Properties\Settings.Designer.cs">
105+
<AutoGen>True</AutoGen>
106+
<DependentUpon>Settings.settings</DependentUpon>
107+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
108+
</Compile>
109+
<EmbeddedResource Include="Properties\Resources.resx">
110+
<Generator>ResXFileCodeGenerator</Generator>
111+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
112+
</EmbeddedResource>
113+
<None Include="Properties\Settings.settings">
114+
<Generator>SettingsSingleFileGenerator</Generator>
115+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
116+
</None>
117+
</ItemGroup>
118+
<ItemGroup>
119+
<None Include="App.config" />
120+
</ItemGroup>
121+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
122+
<ItemGroup>
123+
<Reference Include="Syncfusion.Licensing" />
124+
</ItemGroup>
125+
<ItemGroup />
126+
<ItemGroup>
127+
<Resource Include="Images\collapse.png" />
128+
<Resource Include="Images\expand.png" />
129+
<Resource Include="Images\treeview_exe.png" />
130+
<Resource Include="Images\treeview_folder.png" />
131+
<Resource Include="Images\treeview_img0.png" />
132+
<Resource Include="Images\treeview_img1.png" />
133+
<Resource Include="Images\treeview_mp3.png" />
134+
<Resource Include="Images\treeview_pdf.png" />
135+
<Resource Include="Images\treeview_png.png" />
136+
<Resource Include="Images\treeview_ppt.png" />
137+
<Resource Include="Images\treeview_video.png" />
138+
<Resource Include="Images\treeview_word.png" />
139+
<Resource Include="Images\treeview_zip.png" />
140+
</ItemGroup>
141+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoFitContent_2010", "AutoFitContent_2010.csproj", "{32C01585-2D4A-4D70-A995-83DEAD479CF6}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Debug-Xml|Any CPU = Debug-Xml|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
Release-Xml|Any CPU = Release-Xml|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Debug-Xml|Any CPU.ActiveCfg = Debug|Any CPU
17+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Debug-Xml|Any CPU.Build.0 = Debug|Any CPU
18+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
21+
{3BC5F7F2-64B9-4F32-934D-BA0026BA85E7}.Release-Xml|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
GlobalSection(ExtensibilityGlobals) = postSolution
27+
SolutionGuid = {83543171-DAA1-4E4D-8E1F-70EB2EFAF2A4}
28+
EndGlobalSection
29+
EndGlobal

0 commit comments

Comments
 (0)