2017-07-30 92 views
-2

以下のコードではパフォーマンス上の問題があります。 2つのDataGridで2つのリストをバインドしようとしています。各リストのDataGrid。私はバインディングの2つの方法が必要です。なぜ誰が知っていますか?またはsbにアドバイスがありますか?C#WPFデータバインディングDataGrid遅い

これらは、これはこれはDataGrid.Itemsでデータグリッドを更新し、私の分離コード

  this.DataGridVertices.ItemsSource = AllVerticesList; 
     this.DataGridEdges.ItemsSource = AllEdgesList; 

I'amあるXAML

<DataGrid x:Name="DataGridVertices" Grid.Row="1" Grid.Column="3" BorderBrush="AliceBlue" BorderThickness="5" AutoGenerateColumns="True" ItemsSource="{Binding AllVerticesList}" /> 
    <DataGrid x:Name="DataGridEdges" Grid.Row="2" Grid.Column="3" BorderBrush="AliceBlue" BorderThickness="5" AutoGenerateColumns="True" ItemsSource="{Binding AllEdgesList}" /> 

の私のコードで私のクラス

public class Vertices 
{ 
    public int ID { get; set; } 
    public double PositionX { get; set; } 
    public double PositionY { get; set; } 
    public string Description { get; set; } 
    public bool IsMap { get; set; } 
    public bool IsStartEndPoint { get; set; } 
    public bool IsDisplay { get; set; } 
    public bool IsExit { get; set; } 
    public string TextToSpeech { get; set; } 

} 

public class Edges 
{ 
    public int ID { get; set; } 
    public int SourceVertex { get; set; } 
    public int TargetVertex { get; set; } 
    public bool IsNormal { get; set; } 
    public bool IsElevatorUp { get; set; } 
    public bool IsElevatorDown { get; set; } 
    public bool IsStairUp { get; set; } 
    public bool IsStairDown { get; set; } 
} 

です。リフレッシュ();

ありがとうございます!

答えて

1

データグリッドをリストでバインドする代わりに、ObservableCollectionでバインドします。 バインディングモードをTwoWayに、UpdateSourceTriggerをPropertyChangedに設定します。これで、Datagridをリフレッシュする必要がなくなり、コード内にitemsourceを設定する必要がなくなりました。コレクションを追加、削除するだけです。パフォーマンスが向上します。

バインディングを使用している場合は、コードビハインドを使用しないでください。コードビハインド経由ですべてを管理し、バインディングを使用しないでください。両方を使用すると、パフォーマンスに影響を与える可能性があります。お役に立てれば。

+0

と、アイテムを適切に仮想化していることを確認してください。https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.enablerowvirtualization(v=vs.110).aspx –

+0

完全な追加範囲を持つカスタムObservableCollectionを実装して、新しい要素ごとに1つのイベントではなく、1つのイベントのみを発生させました。 – pix

関連する問題