-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from SyncfusionExamples/WPF-875642-KBSamples
WPF-875642-To add the Samples For KB
- Loading branch information
Showing
60 changed files
with
3,034 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# RestrictNodeFromContainer sample | ||
|
||
This sample explains how to restrict node is being removed from its parent container when dragging. | ||
|
||
__*Documentation*__: https://help.syncfusion.com/wpf/diagram/container | ||
|
||
## Project pre-requisites | ||
To run this application, you need to have the below two in your system | ||
|
||
* [Visual Studio 2019](https://www.visualstudio.com/wpf-vs) | ||
* [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). | ||
|
||
## Deploying and running the sample | ||
* 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. |
25 changes: 25 additions & 0 deletions
25
...ntainer/RestrictNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34309.116 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestrictNodeFromContainer", "RestrictNodeFromContainer\RestrictNodeFromContainer.csproj", "{69520CAF-FA5D-42BC-9D32-A7ACB2259509}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{69520CAF-FA5D-42BC-9D32-A7ACB2259509}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{69520CAF-FA5D-42BC-9D32-A7ACB2259509}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{69520CAF-FA5D-42BC-9D32-A7ACB2259509}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{69520CAF-FA5D-42BC-9D32-A7ACB2259509}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {5BAE0B49-4312-4887-B241-C0F900EB9495} | ||
EndGlobalSection | ||
EndGlobal |
6 changes: 6 additions & 0 deletions
6
.../RestrictNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> | ||
</startup> | ||
</configuration> |
9 changes: 9 additions & 0 deletions
9
...er/RestrictNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/App.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="RestrictNodeFromContainer.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:RestrictNodeFromContainer" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
17 changes: 17 additions & 0 deletions
17
...RestrictNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/App.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace RestrictNodeFromContainer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...rictNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/MainWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Window x:Class="RestrictNodeFromContainer.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:RestrictNodeFromContainer" | ||
xmlns:syncfusion="http://schemas.syncfusion.com/wpf" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="450" Width="800"> | ||
<Window.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
<Style TargetType="syncfusion:Node"> | ||
<Setter Property="ShapeStyle"> | ||
<Setter.Value> | ||
<Style TargetType="Path"> | ||
<Setter Property="Fill" | ||
Value="#FF5B9BD5" /> | ||
<Setter Property="Stretch" | ||
Value="Fill" /> | ||
</Style> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
<Style TargetType="syncfusion:ContainerHeader"> | ||
<Setter Property="ShapeStyle"> | ||
<Setter.Value> | ||
<Style TargetType="Path"> | ||
<Setter Property="Fill" Value="#FF5B9BD5"/> | ||
<Setter Property="Stretch" Value="Uniform"/> | ||
<Setter Property="Data"> | ||
<Setter.Value> | ||
<RectangleGeometry Rect="10,10,10,10"/> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> | ||
</Window.Resources> | ||
<Grid> | ||
<syncfusion:SfDiagram x:Name="diagram" | ||
Nodes="{Binding Nodes}" | ||
Groups="{Binding Groups}" | ||
Connectors="{Binding Connectors}"> | ||
|
||
</syncfusion:SfDiagram> | ||
</Grid> | ||
</Window> |
146 changes: 146 additions & 0 deletions
146
...tNodeFromContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/MainWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using Syncfusion.UI.Xaml.Diagram; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace RestrictNodeFromContainer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
diagram.Groups = new GroupCollection(); | ||
diagram.Nodes = new NodeCollection(); | ||
(diagram.Info as IGraphInfo).NodeChangedEvent += MainWindow_NodeChangedEvent; | ||
(diagram.Info as IGraphInfo).ItemAdded += MainWindow_ItemAdded; | ||
CustomNodeVM node1 = new CustomNodeVM() | ||
{ | ||
ID = "Node1", | ||
UnitWidth = 100, | ||
UnitHeight = 100, | ||
OffsetX = 250, | ||
OffsetY = 260, | ||
//Specify shape to the Node from built-in Shape Dictionary | ||
Shape = this.Resources["Rectangle"], | ||
|
||
}; | ||
|
||
//Add Node to Nodes property of the Diagram | ||
(diagram.Nodes as NodeCollection).Add(node1); | ||
|
||
|
||
CustomNodeVM node2 = new CustomNodeVM() | ||
{ | ||
ID = "Node2", | ||
UnitWidth = 100, | ||
UnitHeight = 100, | ||
OffsetX = 380, | ||
OffsetY = 380, | ||
//Specify shape to the Node from built-in Shape Dictionary | ||
Shape = this.Resources["Rectangle"], | ||
|
||
}; | ||
|
||
//Add Node to Nodes property of the Diagram | ||
(diagram.Nodes as NodeCollection).Add(node2); | ||
|
||
|
||
ObservableCollection<GroupViewModel> groups = new ObservableCollection<GroupViewModel>(); | ||
ContainerViewModel container = new ContainerViewModel() | ||
{ | ||
Nodes = new ObservableCollection<CustomNodeVM>() { node1, node2 }, | ||
UnitHeight = 300, | ||
UnitWidth = 300, | ||
OffsetX = 300, | ||
OffsetY = 300, | ||
}; | ||
container.Header = new ContainerHeaderViewModel() | ||
{ | ||
UnitHeight = 30, | ||
|
||
Annotation = new AnnotationEditorViewModel() | ||
{ | ||
Content = "Container Header", | ||
FontSize = 16, | ||
FontWeight = FontWeights.Bold, | ||
Foreground = Brushes.Black, | ||
ReadOnly = true, | ||
}, | ||
}; | ||
groups.Add(container); | ||
diagram.Groups = groups; | ||
} | ||
|
||
private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args) | ||
{ | ||
if (args.Item is ContainerViewModel) | ||
{ | ||
var container = (ContainerViewModel)args.Item; | ||
if ((container.Nodes as IEnumerable<object>).Any()) | ||
{ | ||
foreach (var item in container.Nodes as IEnumerable<object>) | ||
{ | ||
var node = item as CustomNodeVM; | ||
//setting parent container to the nodes. | ||
node.ParentContainer = container; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void MainWindow_NodeChangedEvent(object sender, ChangeEventArgs<object, NodeChangedEventArgs> args) | ||
{ | ||
if (args.Item is CustomNodeVM && !(args.Item is ContainerViewModel)) | ||
{ | ||
var node = args.Item as CustomNodeVM; | ||
if (node.ParentContainer != null && args.NewValue.InteractionState == NodeChangedInteractionState.Dragging) | ||
{ | ||
ContainerViewModel parentcontainer = node.ParentContainer as ContainerViewModel; | ||
Rect parentContainerBounds = (parentcontainer.Info as IContainerInfo).Bounds; | ||
//Setting Node’s parent container bounds region value to BoundaryConstraint property. | ||
args.BoundaryConstraints = new Rect(parentContainerBounds.Left + 5, parentContainerBounds.Top + 45, | ||
parentContainerBounds.Width - 10, parentContainerBounds.Height - 50); | ||
} | ||
} | ||
} | ||
} | ||
public class CustomNodeVM : NodeViewModel | ||
{ | ||
private ContainerViewModel parentContainer = null; | ||
|
||
/// <summary> | ||
/// Gets or sets the Parent Container of the Node. | ||
/// </summary> | ||
public ContainerViewModel ParentContainer | ||
{ | ||
get | ||
{ | ||
return parentContainer; | ||
} | ||
set | ||
{ | ||
if (parentContainer != value) | ||
{ | ||
parentContainer = value; | ||
OnPropertyChanged("ParentContainer"); | ||
} | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...mContainer/RestrictNodeFromContainer/RestrictNodeFromContainer/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("RestrictNodeFromContainer")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("RestrictNodeFromContainer")] | ||
[assembly: AssemblyCopyright("Copyright © 2024")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
//In order to begin building localizable applications, set | ||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | ||
//inside a <PropertyGroup>. For example, if you are using US english | ||
//in your source files, set the <UICulture> to en-US. Then uncomment | ||
//the NeutralResourceLanguage attribute below. Update the "en-US" in | ||
//the line below to match the UICulture setting in the project file. | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] | ||
|
||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.