Bio*_*der 7 data-binding wpf visual-studio-2010 vspackage graph-sharp
我目前正在开发一个Visual Studio插件(VSPackage),它最终应该能够可视化调用关系.为了表示它们,我想使用管理图形的Graph#库(避免重叠边缘等).不幸的是,我在运行时在我的XAML中收到以下错误消息:
XamlParseException:未实现方法或操作.
<graph:CallRelationGraphLayout Graph="{Binding RelationGraph}"/>
标签上会弹出错误.
<UserControl x:Class="Biocoder.InteractiveExploration.View.ExplorationControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
xmlns:graph="clr-namespace:Biocoder.InteractiveExploration.Graph"
xmlns:viewmodels="clr-namespace:Biocoder.InteractiveExploration.ViewModel"
xmlns:controls="clr-namespace:Biocoder.InteractiveExploration.Controls" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<viewmodels:ExplorationToolViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<zoom:ZoomControl Grid.Row="1"
Zoom="0.2"
ZoomBoxOpacity="0.5"
Background="Yellow">
<graph:CallRelationGraphLayout Graph="{Binding RelationGraph}"/>
</zoom:ZoomControl>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我还创建了自己的顶点,边和图布局类.我的图最终应该表示方法(顶点)之间的调用关系(边).
MethodVertex.cs
public class MethodVertex
{
public string ID { get; private set; }
public bool IsMale { get; private set; }
public MethodVertex(string id, bool isMale)
{
ID = id;
IsMale = isMale;
}
public override string ToString()
{
return string.Format("{0}-{1}", ID, IsMale);
}
}
Run Code Online (Sandbox Code Playgroud)
RelationEdge.cs
public class RelationEdge : Edge<MethodVertex>
{
public string Id { get; private set; }
public RelationEdge(string id, MethodVertex source, MethodVertex target)
: base(source, target)
{
Id = id;
}
}
Run Code Online (Sandbox Code Playgroud)
CallRelationGraphLayout.cs
public class CallRelationGraphLayout : GraphLayout<MethodVertex, RelationEdge, CallRelationGraph>
{}
Run Code Online (Sandbox Code Playgroud)
CallRelationGraph.cs
public class CallRelationGraph : BidirectionalGraph<MethodVertex, RelationEdge>
{
public CallRelationGraph()
{}
public CallRelationGraph(bool allowParallelEdges)
: base(allowParallelEdges)
{ }
public CallRelationGraph(bool allowParallelEdges, int vertexCapacity)
: base(allowParallelEdges, vertexCapacity)
{}
}
Run Code Online (Sandbox Code Playgroud)
在ExplorationToolViewModel中,我将RelationGraph声明如下:
private CallRelationGraph _relationGraph;
public CallRelationGraph RelationGraph
{
get { return _relationGraph; }
set
{
if (value != _relationGraph)
{
_relationGraph = value;
NotifyPropertyChanged("RelationGraph");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
我可能还应该提到的是,我有时会显示以下错误,但项目编译并运行.
GenericArguments [1],'Biocoder.InteractiveExploration.Graph.RelationEdge','GraphSharp.Algorithms.Layout.ILayoutAlgorithm`3 [TVertex,TEdge,TGraph]'违反了'TEdge'类型的约束.
也许它是问题的根源但是我到目前为止忽略它,因为它编译并且我对应于本教程.
奇怪的是它实际上在使用Graph#提供的DLL的普通WPF应用程序中工作.当我离开Graph-property时,错误没有出现,所以我猜它与Graph属性有关.关于如何解决这个问题的任何提示?
非常感谢你提前!
我在 VSPackage 中使用 Graph# 时遇到了同样的问题。我通过不使用图表的绑定,而是通过Graph
在 CodeBehind 中分配属性来解决这个问题。
这导致了分配属性时无法加载 WPFExtensions 程序集的异常Graph
。我怀疑其原因是在 GraphSharp.Controls 中,在 XAML 中使用了程序集,但在编译时未添加引用,因为代码中没有引用。我可以通过在分配属性之前添加以下行来解决此问题Graph
:
var a = System.Reflection.Assembly.Load("WPFExtensions, Version=1.0.3437.34043, Culture=neutral, PublicKeyToken=null");
Run Code Online (Sandbox Code Playgroud)
此行在 WPF 尝试根据 XAML 中的引用加载 WPFExtensions 库之前加载它。随后,图表被展示出来。