グラフを使用したグラフレイアウト#
-
14-11-2019 - |
質問
これはウィンドウのための私のコードです:
public partial class MainWindow
{
private MainWindowViewModel _mainWindowViewModel;
public MainWindow()
{
InitializeComponent();
_mainWindowViewModel = new MainWindowViewModel();
DataContext = _mainWindowViewModel;
}
}
.
とビューモデルコード:
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));
}
}
.
ViewModelBaseクラス:
class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
.
そしてここでxaml:
<Controls:GraphLayout x:Name="graphLayout" Grid.Row="1" LayoutAlgorithmType="FR" OverlapRemovalAlgorithmType="FSA" HighlightAlgorithmType="Simple" Graph="{Binding Path=Graph}" />
.
問題は、このレイアウトの中で物事を見ることができないということです。多分私は間違った方法でデータをバインドしますか?グラフ#はWPF4で正しく機能しますか?
更新:コードを更新しましたが、グラフレイアウトでは何も見ません。
解決済み:グラフを正しく表示するためのカスタムグラフレイアウトを追加する必要があります
.public class CustomGraphLayout : GraphLayout<string, IEdge<string >, BidirectionalGraph<string, IEdge<string>>> {}
解決
public BidirectionalGraph<string, IEdge<string>> Graph { get; set; }
.
ここには、INotifyPropertyChanged
がありません。代わりにこれを使用してください
private BidirectionalGraph<string, IEdge<string>> _graph;
public BidirectionalGraph<string, IEdge<string>> Graph
{
get { return _graph; }
set
{
_graph = value;
NotifyPropertyChanged("Graph");
}
}
.
サポートしているINotifyPropertyChanged
実装ボイラプレートを確実に持っていることを確認してください。
public class MainWindowViewModel : INotifyPropertyChanged
.
と
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
. 所属していません StackOverflow