Skip to content

Commit 1b189da

Browse files
Merge pull request #98 from SatishRaj4377/WPF-879597-Restrict_Node_Dragging_From_Group_Sample
WPF-879597-Added Sample of RestrictNodeDraggingFromGroup
2 parents 70d2d4a + b200595 commit 1b189da

15 files changed

+698
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Restrict Node Dragging in Group
2+
This repository contains sample which shows how to restict node being dragged from group in SfDiagram.
3+
4+
__*Documentation*__: https://help.syncfusion.com/wpf/diagram/group
5+
6+
## Project pre-requisites
7+
To run this application, you need to have the below two in your system
8+
9+
* [Visual Studio 2019](https://www.visualstudio.com/wpf-vs)
10+
* [Syncfusion.SfDiagram.WPF](https://www.nuget.org/packages/Syncfusion.SfDiagram.WPF/) nuget package. To install the package using NuGet Package Manager, refer this [link](https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio#nuget-package-manager).
11+
12+
## Deploying and running the sample
13+
* To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging.
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.6.2" />
5+
</startup>
6+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="RestrictChildDraggingInGroup.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:RestrictChildDraggingInGroup"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 RestrictChildDraggingInGroup
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="RestrictChildDraggingInGroup.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:RestrictChildDraggingInGroup"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800" WindowState="Maximized">
9+
<Window.Resources>
10+
<Style x:Key="parentStyle" TargetType="Path">
11+
<Setter Property="Fill" Value="DodgerBlue"/>
12+
<Setter Property="Stretch" Value="Fill"/>
13+
</Style>
14+
<Style x:Key="childStyle" TargetType="Path">
15+
<Setter Property="Fill" Value="Blue"/>
16+
<Setter Property="Stretch" Value="Fill"/>
17+
</Style>
18+
</Window.Resources>
19+
<Grid>
20+
<local:CustomDiagram x:Name="Diagram"/>
21+
</Grid>
22+
</Window>
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using Syncfusion.UI.Xaml.Diagram;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace RestrictChildDraggingInGroup
19+
{
20+
/// <summary>
21+
/// Interaction logic for MainWindow.xaml
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
public MainWindow()
26+
{
27+
InitializeComponent();
28+
29+
30+
NodeViewModel parentNode = new NodeViewModel()
31+
{
32+
UnitWidth = 300,
33+
UnitHeight = 300,
34+
OffsetX = 660,
35+
OffsetY = 400,
36+
Annotations = new AnnotationCollection()
37+
{
38+
new AnnotationEditorViewModel()
39+
{
40+
Content = "Parent Node",
41+
Foreground = new SolidColorBrush(Colors.White),
42+
}
43+
},
44+
Shape = new RectangleGeometry() { Rect = new Rect(0, 0, 10, 10) },
45+
ShapeStyle = this.Resources["parentStyle"] as Style
46+
};
47+
48+
NodeViewModel childNode = new NodeViewModel()
49+
{
50+
UnitWidth = 100,
51+
UnitHeight = 100,
52+
OffsetX = 660,
53+
OffsetY = 330,
54+
Annotations = new AnnotationCollection()
55+
{
56+
new AnnotationEditorViewModel()
57+
{
58+
Content = "Child Node",
59+
Foreground = new SolidColorBrush(Colors.White),
60+
}
61+
},
62+
Shape = new RectangleGeometry() { Rect = new Rect(0, 0, 10, 10) },
63+
ShapeStyle = this.Resources["childStyle"] as Style
64+
};
65+
66+
ObservableCollection<GroupViewModel> groups = new ObservableCollection<GroupViewModel>();
67+
GroupViewModel group = new GroupViewModel()
68+
{
69+
OffsetX = 900,
70+
Nodes = new ObservableCollection<NodeViewModel>()
71+
{
72+
parentNode,
73+
childNode
74+
},
75+
};
76+
77+
groups.Add(group);
78+
Diagram.Groups = groups;
79+
}
80+
}
81+
82+
public class CustomDiagram : SfDiagram
83+
{
84+
//Method to return the selector for diagram
85+
protected override Selector GetSelectorForItemOverride(object item)
86+
{
87+
//Assigning custom selector to the diagram
88+
CustomSelector selector = new CustomSelector();
89+
return selector;
90+
}
91+
}
92+
93+
public class CustomSelector : Selector
94+
{
95+
//Method to decide whether the Selection should be done in PointerDown.
96+
protected override void PointerSelection(PointerSelectionArgs args)
97+
{
98+
if (args.PointerMode == PointerMode.Down)
99+
{
100+
//Check whether if we select the Node or not
101+
if (args.Source is NodeViewModel)
102+
{
103+
NodeViewModel node = args.Source as NodeViewModel;
104+
//Check whether the parent group of the parent is null or not
105+
if (node.ParentGroup != null)
106+
{
107+
//Ensure the IsSelected Property of the Parent Group of the Node.
108+
if ((node.ParentGroup as GroupViewModel).IsSelected)
109+
{
110+
//Clear the Selection if we select the group
111+
ClearSelection(Element: args.Source);
112+
}
113+
else
114+
{
115+
Selection(element: args.Source);
116+
}
117+
}
118+
else
119+
{
120+
Selection(element: args.Source);
121+
}
122+
}
123+
else if (args.Source is ConnectorViewModel)
124+
{
125+
Selection(element: args.Source);
126+
}
127+
else if (args.Source is SfDiagram)
128+
{
129+
//Clear the selelction if we select the diagram
130+
ClearSelection(Element: args.Source);
131+
}
132+
}
133+
}
134+
}
135+
136+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
// associated with an assembly.
10+
[assembly: AssemblyTitle("RestrictChildDraggingInGroup")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("RestrictChildDraggingInGroup")]
15+
[assembly: AssemblyCopyright("Copyright © 2025")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly:ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
[assembly: AssemblyVersion("1.0.0.0")]
52+
[assembly: AssemblyFileVersion("1.0.0.0")]

Samples/Group/Restrict Node Dragging In Group/RestrictChildDraggingInGroup/Properties/Resources.Designer.cs

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