Graph#,使顶点不动

时间:2018-11-23 13:19:24

标签: c# xaml graph-sharp

我正在尝试Graph#(graphsharp)库,我需要使添加的顶点不动。看来能解决问题的唯一方法就是将GraphLayout IsEnabled属性设置为false。还有另一种方法可以实现这一目标吗?

例如,我如何在单击顶点时进行交互。该库的文档几乎不存在。

<Window x:Class="GraphSharpDemo.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:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
    xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
    xmlns:local="clr-namespace:GraphSharpDemo"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525"
    x:Name="root">
<Grid>
    <zoom:ZoomControl>
        <graphsharp:GraphLayout x:Name="graphLayout" 
                                Graph="{Binding ElementName=root,Path=GraphToVisualize}"
                                LayoutAlgorithmType="Tree"
                                OverlapRemovalAlgorithmType="FSA"
                                HighlightAlgorithmType="Simple">
        </graphsharp:GraphLayout>
    </zoom:ZoomControl>
</Grid>

public partial class MainWindow : Window
{
    private IBidirectionalGraph<object, IEdge<object>> _graphToVisualize;

    public IBidirectionalGraph<object, IEdge<object>> GraphToVisualize
    {
        get
        {
            return _graphToVisualize;
        }
    }

    public MainWindow()
    {
        CreateGraphToVisualize();
        InitializeComponent();
    }

    private void CreateGraphToVisualize()
    {
        var g = new BidirectionalGraph<object, IEdge<object>>();

        Ellipse[] ellipses = new Ellipse[5];
        Polygon[] triangles = new Polygon[5];

        for (int i = 0; i < 5; i++)
        {
            ellipses[i] = CreateCircle();
            triangles[i] = CreateTriangle(25, 50, 50, 0, 0, 0);
            g.AddVertex(triangles[i]);
            g.AddVertex(ellipses[i]);
        }

        g.AddEdge(new Edge<object>(triangles[0], triangles[1]));
        g.AddEdge(new Edge<object>(triangles[1], triangles[2]));
        g.AddEdge(new Edge<object>(triangles[2], triangles[3]));
        g.AddEdge(new Edge<object>(triangles[1], triangles[4]));
        g.AddEdge(new Edge<object>(triangles[3], ellipses[0]));
        g.AddEdge(new Edge<object>(triangles[3], ellipses[1]));
        g.AddEdge(new Edge<object>(triangles[4], ellipses[2]));
        g.AddEdge(new Edge<object>(triangles[4], ellipses[3]));
        g.AddEdge(new Edge<object>(triangles[4], ellipses[4]));

        _graphToVisualize = g;
    }
}

0 个答案:

没有答案