-2
我在下面的代碼中遇到了性能問題。我試圖用兩個DataGrids綁定兩個列表。每個列表的DataGrid。我需要一個雙向綁定。有誰知道爲什麼?或者有某種建議?C#WPF Databinding DataGrid Slow
這些都是我的班
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; }
}
這是我在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}" />
代碼這是我隱藏
this.DataGridVertices.ItemsSource = AllVerticesList;
this.DataGridEdges.ItemsSource = AllEdgesList;
我'與DataGrid.Items更新DataGrid中。刷新();
謝謝!
,並確保您的虛擬化項目正常https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.enablerowvirtualization(v=vs.110).aspx –
,並確保你已經實現了一個自定義的ObservableCollection,它有一個完美的添加範圍,以便每個新元素只觸發一個事件而不是一個事件。 – pix