2013-02-21 74 views
1

我有一個DataGrid綁定到一個靜態的ListCollectionViewDatagrid的數據綁定

CompassLogView類:

 public static ListCollectionView Compasscollection { 
     get { 
      if (_compasscollection == null) { 
       _compasscollection = 
        new ListCollectionView(LogSession.CompassLogCollection); 
      } 
      return _compasscollection; 
     } 
     set { _compasscollection = value; } 
    } 

綁定

compassLogDataGrid.DataContext = CompassLogView.Compasscollection; 

DataGrid中的XAML:

 <DataGrid x:Name="compassLogDataGrid" 
       ItemsSource="{Binding}" 
       SelectionMode="Single" 
       IsSynchronizedWithCurrentItem="True" 
       SelectedItem="{Binding Path=Synchronizer.CurrentCompassLogDataItem}" 
       Style="{DynamicResource ResourceKey=dataGridStyle}"> 
       ... 
</DataGrid> 

SelectedItem(LINE 5)必須綁定到Synchronizer類別的currentCompassLogDataItem

我已經嘗試過,但似乎不可能。有什麼建議麼?

回答

1
<DataGrid x:Name="compassLogDataGrid" 
      ItemsSource="{Binding}" 
      SelectionMode="Single" 
      IsSynchronizedWithCurrentItem="True" 
      SelectedItem="{Binding Path=CurrentCompassLogDataItem,Source={StaticResource synchronizer} }" 
      Style="{DynamicResource ResourceKey=dataGridStyle}"> 
     <DataGrid.Resources> 
      <local:Synchronizer x:Key="synchronizer"/> 
     </DataGrid.Resources> 
    </DataGrid> 

地方:指定xmlns.I命名空間希望這將有助於