简体   繁体   中英

Datagrid databindings

I have a datagrid binded to a static ListCollectionView

CompassLogView class:

        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 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM