8

我目前正在开发一个 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>

我还创建了自己的顶点、边和图形布局类。我的图表最终应该代表方法(顶点)之间的调用关系(边)。

方法顶点.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);
    }
}

关系边缘.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;
    }
}

CallRelationGraphLayout.cs

public class CallRelationGraphLayout : GraphLayout<MethodVertex, RelationEdge, CallRelationGraph>
{}

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)
    {}
}

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));
}

我可能还应该提到的是,我有时会显示以下错误,但项目会编译并运行。

GenericArguments[1], 'Biocoder.InteractiveExploration.Graph.RelationEdge', on 'GraphSharp.Algorithms.Layout.ILayoutAlgorithm`3[TVertex,TEdge,TGraph]' 违反了 'TEdge' 类型的约束。

也许它是问题的根源,但自从它编译以来我忽略了它,我按照本教程做了它。

奇怪的是,它实际上在使用 Graph# 提供的 DLL 的普通 WPF 应用程序中工作。当我离开 Graph 属性时,错误不会出现,所以我猜它与 Graph 属性有关。关于如何解决这个问题的任何提示?

非常感谢您!

4

2 回答 2

2

I've experienced the same issue when using Graph# in a VSPackage. I was able to overcome the issue by not using Bindings for the graph, but by assigning the Graph property in CodeBehind.

This led to an exception that the WPFExtensions assembly could not be loaded when assigning the Graph property. I suspect that the reason for that is that in GraphSharp.Controls, the assembly is used in XAML, but the reference is not added when compiling as there are no references in code. I was able to fix this by adding the following line before assigning the Graph property:

var a = System.Reflection.Assembly.Load("WPFExtensions, Version=1.0.3437.34043, Culture=neutral, PublicKeyToken=null");

This line loads the WPFExtensions library before WPF tries to load it based on the reference in the XAML. Afterwards, the graph was shown.

于 2014-02-14T16:59:29.133 回答
1

在我的情况下,程序集没有复制到输出文件夹,因为复制本地设置为 false。将 copy local 设置为 true 解决了它。(程序集 A 依赖于没有复制本地标志的程序集 B。)

于 2017-11-30T12:02:02.847 回答