Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据网格数据绑定_C#_Wpf_Data Binding - Fatal编程技术网

C# 数据网格数据绑定

C# 数据网格数据绑定,c#,wpf,data-binding,C#,Wpf,Data Binding,我有一个绑定到静态ListCollectionView的datagrid CompassLogView类: public static ListCollectionView Compasscollection { get { if (_compasscollection == null) { _compasscollection = new ListCollection

我有一个绑定到静态ListCollectionView的datagrid

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行)必须绑定到
Synchronizer
类中的
currentCompassLogDataItem

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


<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中的名称空间。我希望这会有所帮助 local:指定xmlns中的名称空间。我希望这会有所帮助