GraphSharp 简介一
来源:互联网 发布:单片机数码管动态显示 编辑:程序博客网 时间:2024/05/12 11:39
GraphSharp网站给出的介绍:Graph# is a graph layout framework. It contains some layout algorithms and a GraphLayout control for WPF applications.即GraphSharp是一个包含一些布局算法可应用于WPF程序图形布局的框架。
GraphSharp网站给出了一个帮助的博客地址,我把它转到了这里。另外,还有一个帮助视频,我把它放在了这里。在这里再次表达一下对墙和翻墙的感受。。。。。视频中的代码如下:
window.xaml窗体中的代码:
<Window x:Class="GraphSharpLearn1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
Title="MainWindow" Height="350" Width="525"
x:Name="root">
<Grid>
<graphsharp:GraphLayout x:Name="graphlayout"
Graph="{Binding ElementName=root,Path=GraphToVisualize}"/>
</Grid>
</Window>
window.xaml.cs中的代码:
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 QuickGraph;
namespace GraphSharpLearn1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private BidirectionalGraph<object,Edge<object>> _graphToVisualize;
public BidirectionalGraph<object, Edge<object>> GraphToVisualize
{
get { return _graphToVisualize; }
}
public MainWindow()
{
CreateGraphToVisualize();
InitializeComponent();
}
private void CreateGraphToVisualize()
{
var g = new BidirectionalGraph<object, Edge<object>>();
//add the verticles to the graph
string[] verticles = new string[5];
for (int i = 0; i < 5; i++)
{
verticles[i] = i.ToString();
g.AddVertex(verticles[i]);
}
//add some edges to the graph
g.AddEdge(new Edge<object>(verticles[0], verticles[1]));
g.AddEdge(new Edge<object>(verticles[1], verticles[0]));
g.AddEdge(new Edge<object>(verticles[1], verticles[2]));
g.AddEdge(new Edge<object>(verticles[2], verticles[3]));
g.AddEdge(new Edge<object>(verticles[3], verticles[4]));
_graphToVisualize = g;
}
}
}
视频中的TBidirectionalGraph和TEdge在新的QuickGraph中都没了,换成BidirectionalGraph和Edge可以调试通过,却没有显示图形,不知道为什么,找了好久都没有找到问题。
晚上,我有看了我的程序和视频上对了一下,把我自作聪明修改的东西又改了回去,原来TBidirectionalGraph和TEdge是IBidirectionalGraph和IEdge,这样的话图就出来了,如下图示:
点和线的布局是我手动调整的,视频里还有一段程序:
对window中的语句做如下修改:
<Window x:Class="GraphSharpLearn1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
Title="MainWindow" Height="350" Width="525"
x:Name="root">
<Grid>
<graphsharp:GraphLayout x:Name="graphlayout"
Graph="{Binding ElementName=root,Path=GraphToVisualize}"
LayoutAlgorithmType="FR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"/>
</Grid>
</Window>
其实只添加了绿颜色的三行代码,运行效果如下:
这个我没有手动修改过,生成就是这样,很显然,以上三行语句的意思是改变点图的布局、大小和对鼠标位置处的点进行高亮显示(如果你一句一句运行的话可以看出)。
在添加另外两句的时候出现了问题,代码:
<Window x:Class="GraphSharpLearn1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions.Controls"
Title="MainWindow" Height="350" Width="525"
x:Name="root">
<Grid>
<zoom:ZoomControl>
<graphsharp:GraphLayout x:Name="graphlayout"
Graph="{Binding ElementName=root,Path=GraphToVisualize}"
LayoutAlgorithmType="FR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"/>
</zoom:zoomcontrol>
</Grid>
</Window>
新添加的代码段为*色,显示错误:
error MC3074: XML 命名空间“clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions.Controls”中不存在标记“ZoomControl”。 行 9 位置 10.又不懂为什么了,在WPFExtensions.Controls中明明可以找到标记ZoomControl。就到这吧,明天再续,回去了。
有时候问题出现了,你不知道为什么,问题解决了,也不知道怎么回事,上次的bug,今天再次运行的时候,结果就出来了:
显然,新加入语句的意思是添加一个图形大小控制的控件。我想我大概知道为什么是错的,VS2010在输入类名称时是索引输入,如果没有出现索引,就不会识别,不知道我这么想对不对。
视频中涉及到的介绍都在这里了,感觉到这个插件功能很强,比之前那个GraphViz要强挺多的,首先,是功能强大很多,图形显示可以和用户交互,其次是编辑代码的环境明显优于GraphViz。只是找不到一个好的说明书,难道要一个一个把它的功能试出来,这不是又去发明轮子了吗?!
- GraphSharp 简介一
- GraphSharp Tutorials
- 一简介
- 简介(一)
- 简介(一)
- 一、MMX技术简介
- XSL 语法简介(一)
- 嵌入式系统简介一
- 一. 硬盘结构简介
- CMMI简介一
- SquashFS HOWTO (一) ---简介
- Jakarta Struts简介(一)
- SystemVerilog语言简介(一)
- Jakarta Struts简介(一)
- 一、Web Service简介
- C# GDI+简介(一)
- H263简介、基本原理(一)
- CSS 简介(一)
- 如何利用(微软学术)/(google学术)/google网页,聚焦最新科技文献,并获得PDF版
- UIImageView 图片自适应大小
- JSP中四种传递参数的方法
- Java压缩技术(四) GZIP——Java原生实现
- Goldengate添加字段等操作同步实验
- GraphSharp 简介一
- struts2 文件上传
- ocx Exitinstance GdiplusShutdown ActiveX gdi+问
- SQLBindParameter
- 有用的代码
- 输入金额代码
- Oracle数据备份命令
- 软件消费观念上的偏差
- 利用SecureCrt实现win7和vmware下ubuntu通信