Whats wrong with my custom edge?

Mar 23, 2010 at 2:09 PM

Ok. So here is what I have:

public class MyGraph : BidirectionalGraph<MyVertexBase, MyEdgeBase>
    {
        /* nothing to do here... */ 
    }

public class MyGraphLayout : GraphLayout<MyVertexBase, MyEdgeBase, MyGraph>
    {
        /* nothing to do here... */ 
    }

public class MyVertexBase : DependencyObject
    {
        #region IMAGE

        public static readonly DependencyProperty IMAGE_PROPERTY =
           DependencyProperty.Register("IMAGE", typeof(Image), typeof(MyVertexBase));

        public Image Image
        {
            get { return (Image)GetValue(IMAGE_PROPERTY); }
            set { SetValue(IMAGE_PROPERTY, value); }
        }

        #endregion

        #region LABEL

        public static DependencyProperty LABEL_PROPERTY =
            DependencyProperty.Register("LABEL", typeof(string), typeof(MyVertexBase));

        public string LABEL
        {
            get { return (string)GetValue(LABEL_PROPERTY); }
            set { SetValue(LABEL_PROPERTY, value); }
        }

        #endregion

        #region UID
        
        public static DependencyProperty UID_PROPERTY =
            DependencyProperty.Register("UID", typeof(string), typeof(MyVertexBase));

        public string UID
        {
            get { return (string)GetValue(UID_PROPERTY); }
            set { SetValue(UID_PROPERTY, value); }
        }

        #endregion

        #region LEVEL

        public static DependencyProperty LEVEL_PROPERTY =
            DependencyProperty.Register("LEVEL", typeof(int), typeof(MyVertexBase));

        public int LEVEL
        {
            get { return (int)GetValue(LEVEL_PROPERTY); }
            set { SetValue(LEVEL_PROPERTY, value); }
        }

        #endregion
    }

public class MyEdgeBase : Edge<MyVertexBase>
    {

        public MyEdgeBase(MyVertexBase fromvertex, MyVertexBase tovertex)
            : base(fromvertex, tovertex)
        {
            
        }

        #region LABEL

        private string label = String.Empty;

        public string LABEL
        {
            get { return (string)label; }
            set { label = value; }
        }

        #endregion

        #region IMAGE

        private Image image = null;

        public Image IMAGE
        {
            get { return (Image)image; }
            set { image = value; }
        }

        #endregion

    }

And:

<DataTemplate DataType="{x:Type thisApp:MyVertexBase}">
            <Grid MouseDown="MyVertexBase_MouseDown" >
                <StackPanel MouseDown="MyVertexBase_MouseDown" >
                    <ContentControl HorizontalAlignment="Center" Content="{Binding IMAGE}" MouseDown="MyVertexBase_MouseDown" MouseRightButtonDown="MyVertexBase_MouseRightButtonDown"/>
                    <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding LABEL}" MouseDown="MyVertexBase_MouseDown" MouseRightButtonDown="MyVertexBase_MouseRightButtonDown" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate DataType="{x:Type thisApp:MyEdgeBase}">
            <Grid>
                <StackPanel>
                    <ContentControl HorizontalAlignment="Center" Content="{Binding IMAGE}" />
                    <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding LABEL}" />
                </StackPanel>
            </Grid>
        </DataTemplate> 

So. The vertex part works 100%. But trying to set the textbox or image of the edge does work. It does not show.

Can anyone spot the problem? Please.

Thank you.

Mar 24, 2010 at 9:18 AM

Problem solved.

 

Mar 31, 2010 at 10:05 AM

Hi rootme,

I came to the similar problem while working with "edge". I'v got two questions as follows:

1. How to make an edge show some text or something may called label?

2. How to make an event work when double click on the edge?

It will be appreciated if you could give some advices.

 


The following is my code dealing with the edge text and event handler :
<DataTemplate DataType="{x:Type local:MyEdge}">
                <TextBlock MouseLeftButtonDown="TextBlock_MouseLeftButtonDown" Text="{Binding Label}" Tag="{Binding}"  />
</DataTemplate>

and the vertex:

 

public class MyEdge : Edge<MyVertex>
    {
        public string Label
        {
            get;
            private set;
        }

        public MyEdge(string label, AntiPlagVertex source, AntiPlagVertex target)
            : base(source, target)
        {
            Label = label;
        }

    }

 

 

 

Mar 31, 2010 at 10:47 AM

Hey cettur,

Regarding your questions I am going to refer you to this excellent thread: http://graphsharp.codeplex.com/Thread/View.aspx?ThreadId=72119

It has everything you asked for, and I used it for my code. Have a look, try it out, and post back if you have questions.