【问题标题】:Datagrid databindings数据网格数据绑定
【发布时间】:2013-02-21 12:49:51
【问题描述】:

我有一个绑定到静态 ListCollectionView 的数据网格

CompassLogView 类:

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

绑定

compassLogDataGrid.DataContext = CompassLogView.Compasscollection;

数据网格 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 类中。

我试过了,但似乎不可能。有什么建议吗?

【问题讨论】:

    标签: c# wpf data-binding


    【解决方案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中的命名空间。希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-26
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 2011-09-28
      • 2012-10-29
      相关资源
      最近更新 更多