1

我已经将 ObservableCollection <Double?> 绑定到网格中的一列,以及其他一些辅助列。

我的 xml 代码就像

<telerik:RadGridView x:Name="rgvDateTime"
                                 Grid.Row="1"
                                 Grid.ColumnSpan="2"
                                 Height="257"
                                 Margin="{StaticResource MarginsForMostRightControl}"
                                 VerticalAlignment="Top"
                                 AutoExpandGroups="True"
                                 AutoGenerateColumns="False"
                                 CanUserFreezeColumns="False"
                                 CanUserReorderColumns="False"
                                 CanUserResizeColumns="False"
                                 EditTriggers="Default"
                                 HorizontalContentAlignment="Left"
                                 IsFilteringAllowed="False"
                                 ItemsSource="{Binding FlowList}"
                                 RowIndicatorVisibility="Collapsed"
                                 ScrollMode="RealTime"
                                 ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                 ScrollViewer.VerticalScrollBarVisibility="Auto"
                                 SelectionMode="Extended"
                                 SelectionUnit="FullRow"
                                 ShowGroupPanel="False"
                                 Style="{StaticResource GridViewStyle}"
                                 TextBlock.TextAlignment="Left">

              <telerik:RadGridView.Columns>
                <Helpers:RowNumberingHelper Width="Auto"
                                            CellStyle="{StaticResource GridCellRowNumberStyle}"
                                            HeaderCellStyle="{StaticResource GridViewHeaderCellExcelStyle}" />


                <telerik:GridViewDataColumn Width="0.25*"
                                            CellStyle="{StaticResource GridCellControlStyle}"
                                            EditTriggers="CellClick"
                                            DataMemberBinding="{Binding}"
                                            HeaderCellStyle="{StaticResource GridViewHeaderCellExcelStyle}">
                  <telerik:GridViewDataColumn.Header>
                    <StackPanel Orientation="Vertical">
                      <TextBlock Text="Flow" />
                      <StackPanel Orientation="Horizontal">
                        <TextBlock HorizontalAlignment="Left"
                                   VerticalAlignment="Top"
                                   Style="{StaticResource Label}"
                                   Text="(" />

                        <localCtrl:UnitLabel VerticalAlignment="Top"
                                             UnitSystem="{Binding RelativeSource={RelativeSource FindAncestor,
                                                                                                 AncestorType={x:Type Window}},
                                                                  Path=DataContext.CurrUnitSystem,
                                                                  Mode=TwoWay}"
                                             UnitType="Flow" />
                        <TextBlock VerticalAlignment="Top"
                                   Style="{StaticResource Label}"
                                   Text=")" />
                      </StackPanel>
                    </StackPanel>
                  </telerik:GridViewDataColumn.Header>
                  <!--<telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                      <Textbox:NumEdit HorizontalAlignment="Stretch"
                                       VerticalAlignment="Center"
                                       BorderBrush="Transparent"
                                       HorizontalContentAlignment="Left"
                                       MaxLength="8"
                                       Text="{Binding}"
                                       />
                    </DataTemplate>
                  </telerik:GridViewDataColumn.CellTemplate>-->
                </telerik:GridViewDataColumn>

              </telerik:RadGridView.Columns>
            </telerik:RadGridView>

我的视图模型是

public class MyVM : NotificationObject
{   
    /// <summary>
    /// Stores the flow list
    /// </summary>
    private ObservableCollection<double?> flowList = new ObservableCollection<double?>();


    /// <summary>
    /// Gets or sets the flow list.
    /// </summary>
    /// <value>The flow list.</value>
    public ObservableCollection<double?> FlowList
    {
      get
      {
        return this.flowList;
      } // get

      set
      {
        this.flowList = value;
        this.RaisePropertyChanged(() => this.FlowList);
      } // set
    } // FlowList   
}

绑定工作正常,但是当我取消注释 xaml 中的 CellTemaplate 块时,它会因 “双向绑定需要 Path 或 XPath”而崩溃。例外。我无法弄清楚我做错了什么。

4

1 回答 1

0

The default CellTemplate expects a correct Path. Although it is equivalent this works:

DataMemberBinding="{Binding Path=.}"
于 2012-07-18T09:47:20.353 回答