Skip to content

Commit 9960f46

Browse files
Merge pull request #1 from susmitha-sundar/master
How to bring the tree node into view by scrolling in wpf treeview
2 parents 7dd18f5 + 6d76f26 commit 9960f46

26 files changed

+1444
-0
lines changed

TreeNodeBringIntoViewDemo/App.ico

4.19 KB
Binary file not shown.

TreeNodeBringIntoViewDemo/App.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application x:Class="TreeNodeBringIntoViewDemo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
<ResourceDictionary>
7+
8+
</ResourceDictionary>
9+
</Application.Resources>
10+
</Application>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#region Copyright Syncfusion Inc. 2001 - 2011
2+
// Copyright Syncfusion Inc. 2001 - 2011. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Configuration;
11+
using System.Data;
12+
using System.Linq;
13+
using System.Windows;
14+
using Syncfusion.Licensing;
15+
16+
namespace TreeNodeBringIntoViewDemo
17+
{
18+
/// <summary>
19+
/// Interaction logic for App.xaml
20+
/// </summary>
21+
public partial class App : Application
22+
{
23+
public App()
24+
{
25+
SyncfusionLicenseProvider.RegisterLicense(DemoCommon.FindLicenseKey());
26+
}
27+
}
28+
29+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.Input;
7+
8+
namespace TreeNodeBringIntoViewDemo
9+
{
10+
public class RelayCommand : ICommand
11+
{
12+
13+
#region Fields 
14+
readonly Action<object> _execute;
15+
readonly Predicate<object> _canExecute;
16+
#endregion
17+
18+
#region Constructors 
19+
/// <summary> 
20+
/// Creates a new command that can always execute. 
21+
/// </summary> 
22+
/// <param name="execute">The execution logic.</param> 
23+
24+
public RelayCommand(Action<object> execute)
25+
: this(execute, null)
26+
{
27+
}
28+
29+
/// <summary> 
30+
/// Creates a new command. 
31+
/// </summary> 
32+
        /// <param name="execute">The execution logic.</param> 
33+
/// <param name="canExecute">The execution status logic.</param> 
34+
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
35+
{
36+
37+
if (execute == null)
38+
throw new ArgumentNullException("execute");
39+
_execute = execute;
40+
_canExecute = canExecute;
41+
}
42+
#endregion
43+
44+
#region ICommand Members 
45+
46+
public bool CanExecute(object parameter)
47+
{
48+
return _canExecute == null ? true : _canExecute(parameter);
49+
}
50+
51+
public event EventHandler CanExecuteChanged
52+
{
53+
add { CommandManager.RequerySuggested += value; }
54+
remove { CommandManager.RequerySuggested -= value; }
55+
}
56+
57+
public void Execute(object parameter)
58+
{
59+
_execute(parameter);
60+
}
61+
62+
#endregion
63+
}
64+
65+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<Window
2+
x:Class="TreeNodeBringIntoViewDemo.MainWindow"
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:TreeNodeBringIntoViewDemo"
6+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
7+
Title="TreeNode BringIntoView Demo"
8+
Width="600"
9+
Height="600"
10+
Icon="App.ico"
11+
WindowStartupLocation="CenterScreen">
12+
<Window.DataContext>
13+
<local:ViewModel/>
14+
</Window.DataContext>
15+
16+
<Grid>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition/>
19+
<ColumnDefinition Width="200"/>
20+
</Grid.ColumnDefinitions>
21+
<syncfusion:SfTreeView
22+
x:Name="sfTreeView"
23+
Margin="10"
24+
BorderThickness="1"
25+
AutoExpandMode="AllNodes"
26+
BorderBrush="LightGray"
27+
AllowDragging="True"
28+
SelectionMode="Multiple"
29+
ChildPropertyName="Models"
30+
ExpandActionTrigger="Node"
31+
NodePopulationMode="Instant"
32+
ItemTemplateDataContextType="Node"
33+
FocusVisualStyle="{x:Null}"
34+
IsAnimationEnabled="True"
35+
ItemsSource="{Binding Items}" >
36+
<syncfusion:SfTreeView.ItemTemplate>
37+
<DataTemplate>
38+
<Grid>
39+
<TextBlock FontSize="12" VerticalAlignment="Center" Text="{Binding Content.State}"/>
40+
</Grid>
41+
</DataTemplate>
42+
</syncfusion:SfTreeView.ItemTemplate>
43+
</syncfusion:SfTreeView>
44+
<StackPanel Grid.Column="1">
45+
<Button x:Name="BringIntoViewButton" Content="Scroll to the last node" Margin="10" Width="150" Height="30" Command="{Binding BringIntoViewCommand}" CommandParameter="{Binding ElementName=sfTreeView}"/>
46+
</StackPanel>
47+
</Grid>
48+
</Window>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Windows;
2+
using Syncfusion.UI.Xaml.TreeView;
3+
using Syncfusion.Windows.Shared;
4+
5+
namespace TreeNodeBringIntoViewDemo
6+
{
7+
/// <summary>
8+
/// Interaction logic for Window1.xaml
9+
/// </summary>
10+
public partial class MainWindow : Window
11+
{
12+
#region Constructor
13+
public MainWindow()
14+
{
15+
InitializeComponent();
16+
}
17+
#endregion
18+
}
19+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#region Copyright Syncfusion Inc. 2001 - 2011
2+
// Copyright Syncfusion Inc. 2001 - 2011. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using System.Collections.ObjectModel;
9+
using System.Collections.Generic;
10+
using System.ComponentModel;
11+
using Syncfusion.Windows.Shared;
12+
using System.Windows.Media.Imaging;
13+
14+
namespace TreeNodeBringIntoViewDemo
15+
{
16+
public class Model : NotificationObject
17+
{
18+
public Model()
19+
{
20+
Models = new ObservableCollection<Model>();
21+
}
22+
23+
private ObservableCollection<Model> models;
24+
public ObservableCollection<Model> Models
25+
{
26+
get
27+
{
28+
return models;
29+
}
30+
31+
set
32+
{
33+
models = value;
34+
this.RaisePropertyChanged("Models");
35+
}
36+
}
37+
38+
#region TreeViewItemAdv Properties
39+
40+
private string state;
41+
/// <summary>
42+
/// Gets or sets a value indicating the Header of the TreeViewItemAdv.
43+
/// </summary>
44+
public string State
45+
{
46+
get
47+
{
48+
return state;
49+
}
50+
51+
set
52+
{
53+
state = value;
54+
this.RaisePropertyChanged("State");
55+
}
56+
}
57+
58+
59+
#endregion
60+
}
61+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#region Copyright Syncfusion Inc. 2001 - 2011
2+
// Copyright Syncfusion Inc. 2001 - 2011. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using System.Reflection;
9+
using System.Resources;
10+
using System.Runtime.CompilerServices;
11+
using System.Runtime.InteropServices;
12+
using System.Windows;
13+
14+
// General Information about an assembly is controlled through the following
15+
// set of attributes. Change these attribute values to modify the information
16+
// associated with an assembly.
17+
[assembly: AssemblyTitle("TreeNodeBringIntoViewDemo")]
18+
[assembly: AssemblyDescription("")]
19+
[assembly: AssemblyConfiguration("")]
20+
[assembly: AssemblyCompany("Microsoft")]
21+
[assembly: AssemblyProduct("TreeNodeBringIntoViewDemo")]
22+
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
23+
[assembly: AssemblyTrademark("")]
24+
[assembly: AssemblyCulture("")]
25+
26+
// Setting ComVisible to false makes the types in this assembly not visible
27+
// to COM components. If you need to access a type in this assembly from
28+
// COM, set the ComVisible attribute to true on that type.
29+
[assembly: ComVisible(false)]
30+
31+
//In order to begin building localizable applications, set
32+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
33+
//inside a <PropertyGroup>. For example, if you are using US english
34+
//in your source files, set the <UICulture> to en-US. Then uncomment
35+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
36+
//the line below to match the UICulture setting in the project file.
37+
38+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
39+
40+
41+
[assembly: ThemeInfo(
42+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
43+
//(used if a resource is not found in the page,
44+
// or application resource dictionaries)
45+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
46+
//(used if a resource is not found in the page,
47+
// app, or any theme specific resource dictionaries)
48+
)]
49+
50+
51+
// Version information for an assembly consists of the following four values:
52+
//
53+
// Major Version
54+
// Minor Version
55+
// Build Number
56+
// Revision
57+
//
58+
// You can specify all the values or you can default the Build and Revision Numbers
59+
// by using the '*' as shown below:
60+
// [assembly: AssemblyVersion("1.0.*")]
61+
[assembly: AssemblyVersion("1.0.0.0")]
62+
[assembly: AssemblyFileVersion("1.0.0.0")]

TreeNodeBringIntoViewDemo/Properties/Resources.Designer.cs

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)