Skip to content

Commit 1ac433d

Browse files
Merge pull request #96 from SyncfusionExamples/WPF-946343-StencilSaveAndLoadSample
WPF-946343-Need to Prepare a sample for Stencil Save and Load UG
2 parents 914ffaf + 7687f46 commit 1ac433d

18 files changed

+1152
-0
lines changed
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>
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Application x:Class="UserInteraction_Stencil.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+
6+
</Application>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.IO;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Windows;
11+
using Syncfusion.Licensing;
12+
13+
namespace UserInteraction_Stencil
14+
{
15+
/// <summary>
16+
/// Interaction logic for App.xaml
17+
/// </summary>
18+
public partial class App : Application
19+
{
20+
public App()
21+
{
22+
// SyncfusionLicenseProvider.RegisterLicense("");
23+
}
24+
25+
/// <summary>
26+
/// Helper method to find a syncfusion license key from the Common folder
27+
/// </summary>
28+
/// <param name="fileName">File name of the syncfusion license key</param>
29+
/// <returns></returns>
30+
//public static string FindLicenseKey()
31+
//{
32+
// int levelsToCheck = 12;
33+
// string filePath = @"Common\SyncfusionLicense.txt";
34+
35+
// string rootPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase.Replace(@"file:///", ""));
36+
37+
// for (int n = 0; n < levelsToCheck; n++)
38+
// {
39+
// string fileDataPath = System.IO.Path.Combine(rootPath, filePath);
40+
// if (System.IO.File.Exists(fileDataPath))
41+
// return File.ReadAllText(fileDataPath, Encoding.UTF8);
42+
// DirectoryInfo rootDirectory = Directory.GetParent(rootPath);
43+
// if (rootDirectory == null)
44+
// break;
45+
// rootPath = rootDirectory.FullName;
46+
// }
47+
// return string.Empty;
48+
//}
49+
}
50+
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:local="clr-namespace:UserInteraction_Stencil"
4+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
5+
x:Class="UserInteraction_Stencil.MainWindow"
6+
xmlns:System="clr-namespace:System;assembly=mscorlib"
7+
xmlns:viewmodel="clr-namespace:UserInteraction_Stencil.Viewmodel"
8+
xmlns:Stencil="clr-namespace:Syncfusion.UI.Xaml.Diagram.Stencil;assembly=Syncfusion.SfDiagram.Wpf"
9+
xmlns:RulerControl="clr-namespace:Syncfusion.UI.Xaml.Diagram.Controls;assembly=Syncfusion.SfDiagram.Wpf"
10+
xmlns:diagram="clr-namespace:Syncfusion.UI.Xaml.Diagram;assembly=Syncfusion.SfDiagram.Wpf"
11+
Icon="App.ico"
12+
Title="Stencil"
13+
WindowState="Maximized"
14+
WindowStartupLocation="CenterScreen">
15+
<Window.DataContext>
16+
<viewmodel:StencilViewModel>
17+
<!--To Represent HorizontalRuler,VerticalRuler-->
18+
<viewmodel:StencilViewModel.HorizontalRuler>
19+
<RulerControl:Ruler Orientation="Horizontal"/>
20+
</viewmodel:StencilViewModel.HorizontalRuler>
21+
22+
<viewmodel:StencilViewModel.VerticalRuler>
23+
<RulerControl:Ruler Orientation="Vertical"/>
24+
</viewmodel:StencilViewModel.VerticalRuler>
25+
26+
<!--Initializes PageSettings-->
27+
<viewmodel:StencilViewModel.PageSettings>
28+
<syncfusion:PageSettings PageBorderBrush="Transparent"/>
29+
</viewmodel:StencilViewModel.PageSettings>
30+
31+
<!--Initializes Node-->
32+
<viewmodel:StencilViewModel.Nodes>
33+
<syncfusion:NodeCollection/>
34+
</viewmodel:StencilViewModel.Nodes>
35+
36+
<!--Initializes Connector-->
37+
<viewmodel:StencilViewModel.Connectors>
38+
<syncfusion:ConnectorCollection/>
39+
</viewmodel:StencilViewModel.Connectors>
40+
41+
<!--Initializes Group-->
42+
<viewmodel:StencilViewModel.Groups>
43+
<syncfusion:GroupCollection/>
44+
</viewmodel:StencilViewModel.Groups>
45+
46+
</viewmodel:StencilViewModel>
47+
</Window.DataContext>
48+
<Window.Resources>
49+
<ResourceDictionary>
50+
<ResourceDictionary.MergedDictionaries>
51+
<!--Initialize Shapes-->
52+
<ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml" />
53+
<ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/Bindingstyle.xaml" />
54+
</ResourceDictionary.MergedDictionaries>
55+
<local:EnumDisplayNameConverter x:Key="EnumDisplayNameConverter"/>
56+
<!--Style for Node-->
57+
<Style TargetType="syncfusion:Node">
58+
<Setter Property="ShapeStyle">
59+
<Setter.Value>
60+
<Style TargetType="Path">
61+
<Setter Property="Fill" Value="#FF5B9BD5"/>
62+
<Setter Property="Stroke" Value="#FFC8C8C8"/>
63+
<Setter Property="Stretch" Value="Fill"/>
64+
</Style>
65+
</Setter.Value>
66+
</Setter>
67+
</Style>
68+
<DataTemplate x:Key="TitleTemplate">
69+
<TextBlock x:Name="HeaderText" Text="{Binding}" FontSize="15" FontWeight="SemiBold" Padding="0,0,0,8">
70+
</TextBlock>
71+
</DataTemplate>
72+
<ObjectDataProvider x:Key="DisplayMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
73+
<ObjectDataProvider.MethodParameters>
74+
<x:Type TypeName="diagram:DisplayMode"/>
75+
</ObjectDataProvider.MethodParameters>
76+
</ObjectDataProvider>
77+
<ObjectDataProvider x:Key="SymbolGroupDisplayMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
78+
<ObjectDataProvider.MethodParameters>
79+
<x:Type TypeName="diagram:SymbolGroupDisplayMode"/>
80+
</ObjectDataProvider.MethodParameters>
81+
</ObjectDataProvider>
82+
<ObjectDataProvider x:Key="SymbolsDisplayMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
83+
<ObjectDataProvider.MethodParameters>
84+
<x:Type TypeName="diagram:SymbolsDisplayMode"/>
85+
</ObjectDataProvider.MethodParameters>
86+
</ObjectDataProvider>
87+
<ObjectDataProvider x:Key="SymbolSelectionMode" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
88+
<ObjectDataProvider.MethodParameters>
89+
<x:Type TypeName="diagram:SymbolSelectionMode"/>
90+
</ObjectDataProvider.MethodParameters>
91+
</ObjectDataProvider>
92+
</ResourceDictionary>
93+
</Window.Resources>
94+
95+
<Grid>
96+
<Grid.ColumnDefinitions>
97+
<ColumnDefinition Width="Auto"/>
98+
<ColumnDefinition Width="3*"/>
99+
<ColumnDefinition Width="*"/>
100+
</Grid.ColumnDefinitions>
101+
102+
103+
<syncfusion:Stencil x:Name="stencil" Width="250" Title="Shapes" TitleTemplate="{StaticResource TitleTemplate}"
104+
SymbolGroupDisplayMode="{Binding SymbolGroupDisplayMode, Mode=TwoWay}"
105+
SymbolSelectionMode="{Binding SymbolSelectionMode, Mode=TwoWay}"
106+
DisplayMode="{Binding DisplayMode, Mode=TwoWay}"
107+
ShowSearchTextBox="{Binding ShowSearchTextBox}"
108+
ShowDisplayModeToggleButton="{Binding ShowDisplayModeToggleButton}"
109+
SymbolsDisplayMode="{Binding SymbolsDisplayMode,Mode=TwoWay}"
110+
Grid.Column="0"
111+
Grid.Row="1"
112+
Margin="5,5,0,5"
113+
Constraints="{Binding StencilConstraints}"
114+
ExpandMode="One" GroupMappingName="Key">
115+
<!--Initialize the stencil categories-->
116+
<syncfusion:Stencil.SymbolGroups>
117+
<syncfusion:SymbolGroups>
118+
<!--Specify the basic shapes category with title and resource key-->
119+
<syncfusion:SymbolGroupViewModel Name="Basic Shapes" CategorySource="{StaticResource BasicShapes}"/>
120+
<syncfusion:SymbolGroupViewModel Name="Flow Shapes" CategorySource="{StaticResource FlowShapes}"/>
121+
<syncfusion:SymbolGroupViewModel Name="Arrow Shapes" CategorySource="{StaticResource ArrowShapes}"/>
122+
<syncfusion:SymbolGroupViewModel Name="DataFlow Shapes" CategorySource="{StaticResource DataFlowShapes}"/>
123+
</syncfusion:SymbolGroups>
124+
</syncfusion:Stencil.SymbolGroups>
125+
</syncfusion:Stencil>
126+
127+
<!--Initializes Diagram-->
128+
<syncfusion:SfDiagram x:Name="diagram"
129+
Grid.Column="1"
130+
Margin="0,5,5,5"
131+
Nodes="{Binding Nodes}"
132+
Connectors="{Binding Connectors}"
133+
Swimlanes="{Binding Swimlanes}"
134+
Groups="{Binding Groups}"
135+
PageSettings="{Binding PageSettings}"
136+
HorizontalRuler="{Binding HorizontalRuler}"
137+
VerticalRuler="{Binding VerticalRuler}">
138+
<!--SnapConstraints used to Control the Visibility of Gridlines and enable/disable Snapping.-->
139+
<syncfusion:SfDiagram.SnapSettings>
140+
<syncfusion:SnapSettings SnapConstraints="All" SnapToObject="All"/>
141+
</syncfusion:SfDiagram.SnapSettings>
142+
</syncfusion:SfDiagram>
143+
144+
<StackPanel Grid.Column="2" Margin="0,20,0,0">
145+
<Grid>
146+
<Grid.ColumnDefinitions>
147+
<ColumnDefinition Width="165"/>
148+
<ColumnDefinition Width="132"/>
149+
</Grid.ColumnDefinitions>
150+
151+
<Grid.RowDefinitions>
152+
<RowDefinition Height="40"/>
153+
<RowDefinition Height="40"/>
154+
<RowDefinition Height="40"/>
155+
<RowDefinition Height="40"/>
156+
</Grid.RowDefinitions>
157+
<Label Grid.Row="0" Grid.Column="0" FontFamily="Segoe UI" FontWeight="Normal" FontSize="12px" Content="Display Mode"/>
158+
<Label Grid.Row="1" Grid.Column="0" FontFamily="Segoe UI" FontWeight="Normal" FontSize="12px" Content="Symbol Group Display Mode"/>
159+
<Label Grid.Row="2" Grid.Column="0" FontFamily="Segoe UI" FontWeight="Normal" FontSize="12px" Content="Symbol Display Mode"/>
160+
<Label Grid.Row="3" Grid.Column="0" FontFamily="Segeo UI" FontWeight="Normal" FontSize="12px" Content="Symbol Selection Mode"/>
161+
162+
<ComboBox Height="22px" x:Name="DisplayMode" Margin="0,-15,0,0" Grid.Row="0" Grid.Column="1"
163+
ItemsSource="{Binding Source={StaticResource DisplayMode}}" SelectedItem="{Binding DisplayMode,Mode=TwoWay}" >
164+
</ComboBox>
165+
<ComboBox Height="22px" Margin="0,-15,0,0" Grid.Row="1" Grid.Column="1"
166+
ItemsSource="{Binding Source={StaticResource SymbolGroupDisplayMode}}" SelectedItem="{Binding SymbolGroupDisplayMode}">
167+
</ComboBox>
168+
<ComboBox Height="22px" Margin="0,-15,0,0" Grid.Row="2" Grid.Column="1"
169+
SelectedItem="0" SelectionChanged="ComboBox_SelectionChanged" >
170+
<ComboBoxItem Content="Icons Only" IsSelected="True" />
171+
<ComboBoxItem Content="Names Under Icons"/>
172+
</ComboBox>
173+
<ComboBox Height="22px" Margin="0,-15,0,0" Grid.Row="3" Grid.Column="1"
174+
ItemsSource="{Binding Source={StaticResource SymbolSelectionMode}}" SelectedItem="{Binding SymbolSelectionMode}"/>
175+
</Grid>
176+
<CheckBox Margin="0,10,0,10" IsChecked="{Binding ShowSearchTextBox, Mode=TwoWay}" Content="Show Search TextBox"></CheckBox>
177+
<CheckBox x:Name="showGridlines" Margin="0,10,0,10"
178+
IsChecked="{Binding ShowDisplayModeToggleButton, Mode=TwoWay}"
179+
Content="Show Display Mode Toggle Button" >
180+
</CheckBox>
181+
<CheckBox Margin="0,10,0,10" IsChecked="{Binding ShowPreview,Mode=TwoWay}" Content="Show Preview">
182+
<CheckBox.ToolTip>
183+
<ToolTip Placement="Bottom" Content="While dragging symbol to the diagram preview of the dragged item will be shown instead of the original dragged item."/>
184+
</CheckBox.ToolTip>
185+
</CheckBox>
186+
<CheckBox Margin="0,10,0,0" IsChecked="{Binding EnableReorder,Mode=TwoWay}" Content="Enable Symbol Reorder">
187+
<CheckBox.ToolTip>
188+
<ToolTip Placement="Bottom" Content="You can rearrange the symbols within it's symbol group."/>
189+
</CheckBox.ToolTip>
190+
</CheckBox>
191+
192+
<Button x:Name="Save" Content="Save" HorizontalAlignment="Left" Height="40" Click="Save_Click" Width="120" Margin="0,20,0,0"/>
193+
194+
<CheckBox x:Name="LoadSettings" Content="Load Settings" IsChecked="False" HorizontalAlignment="Left" Height="20" Width="120" Margin="0,20,0,0"/>
195+
196+
<Button x:Name="Load" Content="Load" HorizontalAlignment="Left" Height="40" Click="Load_Click" Width="120" Margin="0,10,0,0"/>
197+
</StackPanel>
198+
</Grid>
199+
</Window>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Microsoft.Win32;
2+
using Syncfusion.UI.Xaml.Diagram;
3+
using Syncfusion.UI.Xaml.Diagram.Stencil;
4+
using System;
5+
using System.Collections.ObjectModel;
6+
using System.ComponentModel.DataAnnotations;
7+
using System.Globalization;
8+
using System.IO;
9+
using System.Reflection;
10+
using System.Windows;
11+
using System.Windows.Controls;
12+
using System.Windows.Data;
13+
using System.Windows.Markup;
14+
15+
namespace UserInteraction_Stencil
16+
{
17+
/// <summary>
18+
/// Interaction logic for MainWindow.xaml
19+
/// </summary>
20+
public partial class MainWindow : Window
21+
{
22+
public MainWindow()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
28+
{
29+
ComboBox comboBox = sender as ComboBox;
30+
ComboBoxItem selectedItem = comboBox.SelectedItem as ComboBoxItem;
31+
if (selectedItem.Content.ToString() == "Icons Only")
32+
{
33+
stencil.SymbolsDisplayMode = Syncfusion.UI.Xaml.Diagram.SymbolsDisplayMode.IconsOnly;
34+
}
35+
else
36+
{
37+
stencil.SymbolsDisplayMode = Syncfusion.UI.Xaml.Diagram.SymbolsDisplayMode.NamesUnderIcons;
38+
}
39+
}
40+
41+
private void Save_Click(object sender, RoutedEventArgs e)
42+
{
43+
SaveFileDialog dialog = new SaveFileDialog();
44+
dialog.Title = "Save XAML";
45+
46+
dialog.Filter = "XAML File (*.xaml)|*.xaml";
47+
if (dialog.ShowDialog() == true)
48+
{
49+
using (Stream s = File.Open(dialog.FileName, FileMode.OpenOrCreate))
50+
{
51+
stencil.Save(s);
52+
}
53+
}
54+
}
55+
56+
private void Load_Click(object sender, RoutedEventArgs e)
57+
{
58+
stencil.SymbolGroups = new SymbolGroups();
59+
60+
OpenFileDialog dialog = new OpenFileDialog();
61+
if (dialog.ShowDialog() == true)
62+
{
63+
using (Stream myStream = dialog.OpenFile())
64+
{
65+
stencil.Load(myStream, LoadSettings.IsChecked.Value);
66+
}
67+
}
68+
}
69+
}
70+
71+
public class EnumDisplayNameConverter : IValueConverter
72+
{
73+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
74+
{
75+
if (value == null || value.ToString() == "")
76+
return string.Empty;
77+
78+
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
79+
if (fieldInfo != null)
80+
{
81+
var attributes = fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false);
82+
if (attributes.Length > 0)
83+
{
84+
var attribute = attributes[0] as DisplayAttribute;
85+
if (!String.IsNullOrEmpty(attribute.Name))
86+
return attribute.Name;
87+
else if (!String.IsNullOrEmpty(attribute.ShortName))
88+
return attribute.ShortName;
89+
}
90+
}
91+
return Enum.GetName(value.GetType(), value);
92+
}
93+
94+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
95+
{
96+
throw new NotImplementedException();
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)