syncfusion-diagram:demo1如何实现

2024-04-11 12:52

本文主要是介绍syncfusion-diagram:demo1如何实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
 xmlns:stencil="clr-namespace:Syncfusion.UI.Xaml.Diagram.Stencil;assembly=Syncfusion.SfDiagram.WPF"当我们进入syncfusion的diagram中,可以看到,一个非常炫酷的例子

不仅实现了上方的工具栏同时还有下方的模板栏和画布。

如何实现相同的效果呢

1.注册密钥

syncfusion在使用时需要密钥,首先在visual studio里下生成一个新的wpf工程,加入下面这六个nuget包,看名字就知道第一个是许可证相关的,没有这个你就没法声明许可证密钥。

 ,然后现在,在mainwindow.xaml.cs文件中修改代码。

1.加入

using Syncfusion.UI.Xaml.Diagram;//引用
using Syncfusion.UI.Xaml.Diagram.Layout;//布局管理功能引用
using Syncfusion.UI.Xaml.Diagram.Stencil;//符号库引用

2.在初始化之前加入Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("你申请的许可证密钥");一定要在初始化之前加入。

关于密钥的申请,这篇文章很清楚:

安装和使用_syncfusion的密钥-CSDN博客

using System.Text;
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;
using Syncfusion.UI.Xaml.Diagram;//引用
using Syncfusion.UI.Xaml.Diagram.Layout;//布局管理功能引用
using Syncfusion.UI.Xaml.Diagram.Stencil;//符号库引用namespace syncfusion_24_4_9_demo1
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window{public MainWindow(){Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("你申请的许可证密钥");InitializeComponent();}}
}
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

接下来就能愉快的进行syncfusion的使用了

2.在mainwindow.xaml 的窗口定义部分添加两行代码

 xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
 xmlns:stencil="clr-namespace:Syncfusion.UI.Xaml.Diagram.Stencil;assembly=Syncfusion.SfDiagram.WPF"

  1. xmlns:syncfusion:引入了 syncfusion 命名空间,允许在XAML中使用Syncfusion控件库。
  2. xmlns:stencil:引入了 stencil 命名空间,用于在XAML中使用Stencil相关的功能。

效果如下面所示

<Window x:Class="syncfusion_24_4_9_demo1.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:syncfusion_24_4_9_demo1"xmlns:syncfusion="http://schemas.syncfusion.com/wpf"xmlns:stencil="clr-namespace:Syncfusion.UI.Xaml.Diagram.Stencil;assembly=Syncfusion.SfDiagram.WPF"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800">

3.定义窗口的资源

在窗口的资源中定义一个资源字典,先把basicshapes.xaml这个资源字典加入当前资源字典,然后定义node的样式,connector的样式,symbol的样式,然后定义了一个数据模板,用来统一标题。

注:style-样式,只是统一控件的某些属性,templete-模板,则是相当于在原有控件基础上改变内部结构和行为。

<Window.Resources><!--定义资源字典和样式--><ResourceDictionary><ResourceDictionary.MergedDictionaries><!--初始化形状--><ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml" /></ResourceDictionary.MergedDictionaries><Style TargetType="syncfusion:Node"><!--定义目标类型为node的风格--><Setter Property="ShapeStyle"><!--内容模板--><Setter.Value><Style TargetType="Path"><Setter Property="Fill" Value="Blue"></Setter><Setter Property="Stretch" Value="Fill"></Setter></Style></Setter.Value></Setter></Style><!--Style for Connector--><Style TargetType="syncfusion:Connector"><!--定义connector的风格--><Setter Property="ConnectorGeometryStyle"><!--形状定义--><Setter.Value><Style TargetType="Path"><Setter Property="Stroke" Value="Black"  /><!--stroke是轮廓--><Setter Property="StrokeThickness" Value="1" /></Style></Setter.Value></Setter><Setter Property="TargetDecoratorStyle"><!--目标描述定义--><Setter.Value><Style TargetType="Path"><!--路径--><Setter Property="Stroke" Value="#4f4f4f"  /><Setter Property="Stretch" Value="Fill" /><Setter Property="Fill" Value="#4f4f4f"  /><Setter Property="StrokeThickness" Value="1" /></Style></Setter.Value></Setter></Style><!--Symbol类型定义--><Style TargetType="stencil:Symbol"><Setter Property="Width" Value="50"/><Setter Property="Height" Value="50"/><Setter Property="Padding" Value="3" /><Setter Property="BorderThickness" Value="1" /><Setter Property="Background" Value="Transparent" /><Setter Property="BorderBrush" Value="Transparent" /><Setter Property="Margin" Value="4"></Setter></Style><DataTemplate x:Key="TitleTemplate"><TextBlock x:Name="HeaderText" Text="{Binding}" FontSize="15" FontWeight="SemiBold"  Foreground="#2b579a" /></DataTemplate></ResourceDictionary>
</Window.Resources>

 4.定义页面

首先把页面划分成两行,第一行放工具栏,这个直接把sfdiagramribbon拖进来就好了,放在第一行,第二行再分成两列,第一列设置成自动宽度,第二列设置成*,因为左边的模板栏可以收缩到页面最左边,所以要设置成auto,这样缩进的时候占据的空间也会相应的收缩,右边画布设置成*,就是要在左边模板栏收缩的时候,右边也能自动占据空间。

 <Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="*"/></Grid.RowDefinitions><syncfusion:SfDiagramRibbon x:Name="DiagramRibbon" Grid.Row="0" DataContext="{Binding ElementName=Diagram}"/><Grid Grid.Row="1"><Grid.ColumnDefinitions><ColumnDefinition Width="auto"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Grid Grid.Column="0"><Grid Background="White"><stencil:Stencil x:Name="stencil"Grid.Column="0"Grid.Row="1"ExpandMode="ZeroOrMore"BorderBrush="#dfdfdf"BorderThickness="1" Title="Shapes" TitleTemplate="{StaticResource TitleTemplate}"><stencil:Stencil.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><!--初始化形状--><ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml" /></ResourceDictionary.MergedDictionaries></ResourceDictionary></stencil:Stencil.Resources><stencil:Stencil.SymbolSource><syncfusion:SymbolCollection><!--Define the DiagramElement- Node--><syncfusion:NodeViewModel x:Name="node"Key="Nodes"UnitHeight="70"UnitWidth="100"OffsetX="100"OffsetY="100"Shape="{StaticResource Rectangle}"></syncfusion:NodeViewModel><!--Define the DiagramElement- Connector--><syncfusion:ConnectorViewModel SourcePoint="100,100"Key="Connectors"TargetPoint="200,200" /><!--Define the DiagramElement- Group--><syncfusion:GroupViewModel Key="Groups"><!--Creates the Groupable Nodes--><syncfusion:GroupViewModel.Nodes><syncfusion:NodeCollection><syncfusion:NodeViewModel UnitHeight="70"ID="srcnode"OffsetX="0"OffsetY="300"UnitWidth="100"Shape="{StaticResource Rectangle}"></syncfusion:NodeViewModel><syncfusion:NodeViewModel UnitHeight="70"ID="tarnode"OffsetX="100"OffsetY="500"UnitWidth="100"Shape="{StaticResource Rectangle}"></syncfusion:NodeViewModel></syncfusion:NodeCollection></syncfusion:GroupViewModel.Nodes><!--Creates the Groupable Connectors--><syncfusion:GroupViewModel.Connectors><syncfusion:ConnectorCollection><syncfusion:ConnectorViewModel SourceNodeID="srcnode"TargetNodeID="tarnode" /></syncfusion:ConnectorCollection></syncfusion:GroupViewModel.Connectors></syncfusion:GroupViewModel></syncfusion:SymbolCollection></stencil:Stencil.SymbolSource><stencil:Stencil.Categories><stencil:StencilCategoryCollection><!--Specify the basic shapes category with title and resource key--><stencil:StencilCategory Title="Basic Shapes" Keys="{StaticResource BasicShapes}"/></stencil:StencilCategoryCollection></stencil:Stencil.Categories><stencil:Stencil.SymbolGroups><stencil:SymbolGroups><!--Separate groups based on the key--><stencil:SymbolGroupProvider MappingName="Key" /></stencil:SymbolGroups></stencil:Stencil.SymbolGroups></stencil:Stencil></Grid></Grid><syncfusion:SfDiagram x:Name="Diagram" Constraints="Undoable,Default" Grid.Column="1"><syncfusion:SfDiagram.Theme><syncfusion:OfficeTheme/></syncfusion:SfDiagram.Theme><syncfusion:SfDiagram.Nodes><syncfusion:NodeCollection/></syncfusion:SfDiagram.Nodes><syncfusion:SfDiagram.Connectors><syncfusion:ConnectorCollection/></syncfusion:SfDiagram.Connectors><syncfusion:SfDiagram.Groups><syncfusion:GroupCollection/></syncfusion:SfDiagram.Groups><syncfusion:SfDiagram.SnapSettings><syncfusion:SnapSettings SnapConstraints="All"/></syncfusion:SfDiagram.SnapSettings><syncfusion:SfDiagram.HorizontalRuler><syncfusion:Ruler Orientation="Horizontal"/></syncfusion:SfDiagram.HorizontalRuler><syncfusion:SfDiagram.VerticalRuler><syncfusion:Ruler Orientation="Vertical"/></syncfusion:SfDiagram.VerticalRuler></syncfusion:SfDiagram></Grid></Grid>

这篇关于syncfusion-diagram:demo1如何实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/894136

相关文章

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

Python位移操作和位运算的实现示例

《Python位移操作和位运算的实现示例》本文主要介绍了Python位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义