Skip to content

Commit 9de39db

Browse files
How to bind selected items in wpf treeview
1 parent 0225290 commit 9de39db

25 files changed

+1403
-0
lines changed

SfTreeViewMVVMSelection/App.ico

4.19 KB
Binary file not shown.

SfTreeViewMVVMSelection/App.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application x:Class="TreeViewMVVMselectionDemo.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 CheckedTreeViewDemo
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Window
2+
x:Class="TreeViewMVVMselectionDemo.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:TreeViewMVVMselectionDemo"
6+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
7+
Title="TreeView MVVM selection"
8+
Width="450"
9+
Height="600"
10+
Icon="App.ico"
11+
WindowStartupLocation="CenterScreen">
12+
13+
<Window.DataContext>
14+
<local:ViewModel/>
15+
</Window.DataContext>
16+
17+
<Grid>
18+
<syncfusion:SfTreeView
19+
x:Name="treeView"
20+
Margin="10"
21+
BorderThickness="1"
22+
AutoExpandMode="AllNodes"
23+
BorderBrush="LightGray"
24+
AllowDragging="True"
25+
SelectionMode="Multiple"
26+
SelectedItems="{Binding SelectedNodes,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
27+
CheckBoxMode ="Recursive"
28+
ChildPropertyName="Models"
29+
ExpandActionTrigger="Node"
30+
ItemTemplateDataContextType="Node"
31+
FocusVisualStyle="{x:Null}"
32+
IsAnimationEnabled="True"
33+
ItemsSource="{Binding Items}" >
34+
35+
<syncfusion:SfTreeView.ItemTemplate>
36+
<DataTemplate>
37+
<Grid>
38+
<TextBlock FontSize="12" VerticalAlignment="Center" Text="{Binding Content.State}" />
39+
</Grid>
40+
</DataTemplate>
41+
</syncfusion:SfTreeView.ItemTemplate>
42+
</syncfusion:SfTreeView>
43+
44+
45+
</Grid>
46+
</Window>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Windows;
2+
using Syncfusion.Windows.Shared;
3+
4+
namespace TreeViewMVVMselectionDemo
5+
{
6+
/// <summary>
7+
/// Interaction logic for Window1.xaml
8+
/// </summary>
9+
public partial class MainWindow : Window
10+
{
11+
#region Constructor
12+
13+
public MainWindow()
14+
{
15+
InitializeComponent();
16+
}
17+
18+
#endregion
19+
}
20+
}
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 TreeViewMVVMselectionDemo
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("CheckedTreeViewDemo")]
18+
[assembly: AssemblyDescription("")]
19+
[assembly: AssemblyConfiguration("")]
20+
[assembly: AssemblyCompany("Microsoft")]
21+
[assembly: AssemblyProduct("CheckedTreeViewDemo")]
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")]

SfTreeViewMVVMSelection/Properties/Resources.Designer.cs

Lines changed: 78 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)