Skip to content

Commit

Permalink
added sample for symbol group view models with menu items.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepathiruppathy01 committed Jun 11, 2024
1 parent db736ab commit 3301087
Show file tree
Hide file tree
Showing 24 changed files with 870 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SymbolGroupViewModel with context menu sample

This sample demonstrate how to create the symbol group view model with context menu lsit to the stencil.

__*Documentation*__: https://help.syncfusion.com/wpf/diagram/serialization
## 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.
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.7.2" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="StencilCategory.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StencilCategory"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
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 StencilCategory
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<Window x:Class="StencilCategory.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:System="clr-namespace:System;assembly=mscorlib"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:diagram="clr-namespace:Syncfusion.UI.Xaml.Diagram;assembly=Syncfusion.SfDiagram.Wpf"
xmlns:viewmodel="clr-namespace:StencilCategory.ViewModel"
xmlns:local="clr-namespace:StencilCategory"
mc:Ignorable="d" WindowState="Maximized"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml"/>
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="Diamond">
<StackPanel>
<Path Stretch="Fill"
Data="M 397.784,287.875L 369.5,316.159L 341.216,287.875L 369.5,259.591L 397.784,287.875 Z"
Fill="White"
Stroke="Black"
StrokeThickness="1" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Diamond" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="symboltemplate">
<StackPanel>
<Image Source="pack://application:,,,/Images/User-Login.png" Width="100" Height="80" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="User" />
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="Sample">
<StackPanel>
<Image Source="pack://application:,,,/Images/Delete.png" Width="100" Height="80" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="User" />
</StackPanel>
</DataTemplate>


<DataTemplate x:Key="TitleTemplate">
<TextBlock x:Name="HeaderText" Text="{Binding}" FontSize="15" FontWeight="SemiBold" Padding="0,0,0,8">
</TextBlock>
</DataTemplate>

<ObjectDataProvider x:Key="SymbolGroupDisplayMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="diagram:SymbolGroupDisplayMode"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>


<Style TargetType="syncfusion:Node">
<Setter Property="ShapeStyle">
<Setter.Value>
<Style TargetType="Path">
<Setter Property="Fill" Value="#FF5B9BD5"/>
<Setter Property="Stretch" Value="Fill"/>
<Setter Property="Stroke" Value="#FFEDF1F6"/>
</Style>
</Setter.Value>
</Setter>
</Style>

<DataTemplate x:Key="textheader">
<Grid RenderTransformOrigin="0.5,0.5">
<TextBlock Padding="8" Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
</Grid>
</DataTemplate>


</ResourceDictionary>
</Window.Resources>
<Window.DataContext>
<viewmodel:StencilViewModel>
<viewmodel:StencilViewModel.HorizontalRuler>
<syncfusion:Ruler Orientation="Horizontal"/>
</viewmodel:StencilViewModel.HorizontalRuler>
<viewmodel:StencilViewModel.VerticalRuler>
<syncfusion:Ruler Orientation="Vertical"/>
</viewmodel:StencilViewModel.VerticalRuler>
<viewmodel:StencilViewModel.PageSettings>
<syncfusion:PageSettings PageBorderBrush="Transparent"/>
</viewmodel:StencilViewModel.PageSettings>
<viewmodel:StencilViewModel.Nodes>
<syncfusion:NodeCollection/>
</viewmodel:StencilViewModel.Nodes>
<viewmodel:StencilViewModel.Connectors>
<syncfusion:ConnectorCollection/>
</viewmodel:StencilViewModel.Connectors>
<viewmodel:StencilViewModel.Groups>
<syncfusion:GroupCollection/>
</viewmodel:StencilViewModel.Groups>
</viewmodel:StencilViewModel>
</Window.DataContext>

<Grid>

<Grid Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Shapes"
FontSize="17"
FontWeight="SemiBold"
Foreground="#2b579a"
HorizontalAlignment="Left"
Margin="10,5,0,5"
Grid.Row="0" />
<syncfusion:Stencil x:Name="stencil11" Grid.Column="0" Grid.Row="1" ExpandMode="ZeroOrMore" BorderBrush="#dfdfdf" BorderThickness="1">
<syncfusion:Stencil.SymbolGroups>
<syncfusion:SymbolGroups>
<syncfusion:SymbolGroupViewModel Name="Basic Shapes" CategorySource="{StaticResource BasicShapes}">
<syncfusion:SymbolGroupViewModel.Menu>
<syncfusion:DiagramMenu>
<syncfusion:DiagramMenu.MenuItems>
<local:DiagramMenuItems>
<syncfusion:DiagramMenuItem Content="Delete" Icon="pack://application:,,,/Images/Delete.png"/>
</local:DiagramMenuItems>
</syncfusion:DiagramMenu.MenuItems>
</syncfusion:DiagramMenu>
</syncfusion:SymbolGroupViewModel.Menu>
</syncfusion:SymbolGroupViewModel>
<syncfusion:SymbolGroupViewModel Name="Flow Shapes" CategorySource="{StaticResource FlowShapes}"/>
<syncfusion:SymbolGroupViewModel Name="Arrow Shapes" CategorySource="{StaticResource ArrowShapes}"/>
<syncfusion:SymbolGroupViewModel Name="DataFlow Shapes" CategorySource="{StaticResource DataFlowShapes}"/>
</syncfusion:SymbolGroups>
</syncfusion:Stencil.SymbolGroups>


<syncfusion:Stencil.SymbolGroupMenu>
<syncfusion:DiagramMenu>
<syncfusion:DiagramMenu.MenuItems>
<local:DiagramMenuItems>
<syncfusion:DiagramMenuItem Content="Move Up" Icon="pack://application:,,,/Images/Arrow Up -03.png" ></syncfusion:DiagramMenuItem>
<syncfusion:DiagramMenuItem Content="Move Down" Icon="pack://application:,,,/Images/Road-Backward.png" ></syncfusion:DiagramMenuItem>
</local:DiagramMenuItems>
</syncfusion:DiagramMenu.MenuItems>


</syncfusion:DiagramMenu>
</syncfusion:Stencil.SymbolGroupMenu>

</syncfusion:Stencil>
</Grid>

<!--Initializes Diagram-->
<syncfusion:SfDiagram x:Name="diagram11"
Grid.Column="1"
Nodes="{Binding Nodes}" Connectors="{Binding Connectors}"

HorizontalRuler="{Binding HorizontalRuler}"
VerticalRuler="{Binding VerticalRuler}">

</syncfusion:SfDiagram>
</Grid>
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using StencilCategory.ViewModel;
using Syncfusion.UI.Xaml.Diagram;
using Syncfusion.UI.Xaml.Diagram.Controls;
using Syncfusion.UI.Xaml.Diagram.Stencil;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.SymbolStore;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Xml.Linq;

namespace StencilCategory
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

private string temp;

public MainWindow()
{
InitializeComponent();
stencil11.Expanded += Stencil11_Expanded1;
stencil11.MenuItemClicked += Stencil_MenuItemClicked;
}

private void Stencil11_Expanded1(object sender, SymbolGroupExpandCollapseEventArgs args)
{
temp = args.GroupName.ToString();
}



private void Stencil_MenuItemClicked(object sender, MenuItemClickedEventArgs args)
{

if (args.Item.Content.ToString() == "Delete")
{
for (int i = 0; i < stencil11.SymbolGroups.Count; i++)
{
var v = stencil11.SymbolGroups[i];
if ((v as SymbolGroupViewModel).Name == temp)
{
stencil11.SymbolGroups.RemoveAt(i);
break;
}
}
}
else
{
for (int i = 0; i < stencil11.SymbolGroups.Count; i++)
{
var v = stencil11.SymbolGroups[i];
if ((v as SymbolGroupViewModel).Name == temp)
{
if (args.Item.Content.ToString() == "Move Up")
{
stencil11.SymbolGroups.Move(i, i - 1);
break;
}
else
{
stencil11.SymbolGroups.Move(i, i + 1);
break;
}
}
}
}
}



private void MainWindow_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{

}
}

public class DiagramMenuItems : ObservableCollection<DiagramMenuItem>
{
public DiagramMenuItems() { }
}


}
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("StencilCategory")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StencilCategory")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[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")]
Loading

0 comments on commit 3301087

Please sign in to comment.