[英]Datagrid databindings
I have a datagrid binded to a static ListCollectionView 我有一个绑定到静态ListCollectionView的datagrid
CompassLogView class: CompassLogView类:
public static ListCollectionView Compasscollection {
get {
if (_compasscollection == null) {
_compasscollection =
new ListCollectionView(LogSession.CompassLogCollection);
}
return _compasscollection;
}
set { _compasscollection = value; }
}
The Binding 绑定
compassLogDataGrid.DataContext = CompassLogView.Compasscollection;
the datagrid Xaml: datagrid Xaml:
<DataGrid x:Name="compassLogDataGrid"
ItemsSource="{Binding}"
SelectionMode="Single"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding Path=Synchronizer.CurrentCompassLogDataItem}"
Style="{DynamicResource ResourceKey=dataGridStyle}">
...
</DataGrid>
the SelectedItem
(LINE 5) must be bound to currentCompassLogDataItem
which is in Synchronizer
class. 必须将SelectedItem
(LINE 5)绑定到Synchronizer
类中的currentCompassLogDataItem
。
I have tried but it seems impossible. 我已经尝试过,但是似乎不可能。 any suggestions? 有什么建议么?
<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: specifies the namespace in xmlns.I hope this will help local:在xmlns中指定名称空间,希望对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.