我有一个绑定到静态ListCollectionView
的数据网格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
(第5行)必须绑定到currentCompassLogDataItem
类中的Synchronizer
。
我试过但似乎不可能。有什么建议吗?
答案 0 :(得分: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>
local:指定xmlns中的命名空间。我希望这会有所帮助