2011-05-16 14 views
5

Aquí está mi código de la ventana:Graph Layout usando Gráfico #

public partial class MainWindow 
{ 
    private MainWindowViewModel _mainWindowViewModel; 

    public MainWindow() 
    { 
     InitializeComponent(); 
     _mainWindowViewModel = new MainWindowViewModel(); 
     DataContext = _mainWindowViewModel; 
    } 
} 

Y el código de vista del modelo:

class MainWindowViewModel : ViewModelBase 
{ 
    private BidirectionalGraph<string, IEdge<string>> _graph; 

    public BidirectionalGraph<string, IEdge<string>> Graph 
    { 
     get { return _graph; } 
     set 
     { 
      _graph = value; 
      NotifyPropertyChanged("Graph"); 
     } 
    } 

    public MainWindowViewModel() 
    { 
     Graph = new BidirectionalGraph<string, IEdge<string>>(); 

     // test data 
     const string vertex1 = "123"; 
     const string vertex2 = "456"; 
     const string vertex3 = "ddd"; 

     Graph.AddVertex(vertex1); 
     Graph.AddVertex(vertex2); 
     Graph.AddVertex(vertex3); 
     Graph.AddEdge(new Edge<string>(vertex1, vertex2)); 
     Graph.AddEdge(new Edge<string>(vertex2, vertex3)); 
     Graph.AddEdge(new Edge<string>(vertex2, vertex1)); 
    } 
} 

clase ViewModelBase:

class ViewModelBase : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    protected void NotifyPropertyChanged(string info) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(info)); 
     } 
    } 
} 

Y aquí va la XAML:

<Controls:GraphLayout x:Name="graphLayout" Grid.Row="1" LayoutAlgorithmType="FR" OverlapRemovalAlgorithmType="FSA" HighlightAlgorithmType="Simple" Graph="{Binding Path=Graph}" /> 

El problema es que no puedo ver nada en este diseño. ¿Tal vez enlace datos de la manera incorrecta? ¿Graph # funciona correctamente con WPF4?

Actualización: He actualizado mi código, pero todavía no veo nada en el diseño del gráfico.

Resuelto: diseño gráfico personalizado debe añadirse para visualizar correctamente el gráfico

public class CustomGraphLayout : GraphLayout<string, IEdge<string >, BidirectionalGraph<string, IEdge<string>>> {} 

Respuesta

2
public BidirectionalGraph<string, IEdge<string>> Graph { get; set; } 

no hay INotifyPropertyChanged aquí. Use este lugar

private BidirectionalGraph<string, IEdge<string>> _graph; 

public BidirectionalGraph<string, IEdge<string>> Graph 
{ 
    get { return _graph; } 
    set 
    { 
     _graph = value; 
     NotifyPropertyChanged("Graph"); 
    } 
} 

y asegurarse de que tienen el apoyo INotifyPropertyChanged aplicación repetitivo

public class MainWindowViewModel : INotifyPropertyChanged 

y

#region INotifyPropertyChanged Implementation 

public event PropertyChangedEventHandler PropertyChanged; 

private void NotifyPropertyChanged(String info) 
{ 
    if (PropertyChanged != null) 
    { 
     PropertyChanged(this, new PropertyChangedEventArgs(info)); 
    } 
} 

#endregion 
+0

Oh, gracias. Trataré de usar 'INotifyPropertyChanged', pero ¿puedo usar' DependencyObject' y 'DependencyProperty' en su lugar? ¿Puedes darme un ejemplo? Gracias de antemano por su respuesta. –

+0

Es mucho más típico en mi experiencia que viewmodels usen INPC, pero aquí hay algunas discusiones sobre el tema http://stackoverflow.com/questions/291518/. En cuanto a las muestras, el sitio graphsharp tiene algunas http://graphsharp.codeplex.com/wikipage?title=Tutorials&referringTitle=Home – kenwarner

+0

Gracias por su comentario, he actualizado mi código, pero todavía no hay ningún resultado. –