尝试编辑DataGrid列时,“双向绑定需要Path或XPath”

时间:2017-03-13 17:56:54

标签: c# wpf datagrid multibinding

我有一个DataGrid,我在其中一个列中进行MultiBinding。只是一点背景 - 我有一个控件(AngleSelectionControl),用户正在选择要在数据网格中显示的单位(度或弧度)。使用下面的代码,Roll2列显示存储在模型中的值(度)。给定所选单位(度或弧度)时,滚动列显示正确的值。这一切都有效。我还可以更改Roll2列值,并更新Roll列并以选定的单位显示。但是,当我尝试编辑Roll列(双击单元格)时,调试器显示异常,说“双向绑定需要Path或XPath”。我错过了什么?

<DataGrid Name="StationConfigurationsDataGrid" Grid.Column="1" Height="150" Width="420" CanUserAddRows="True" AutoGenerateColumns="False" Grid.ColumnSpan="2" ItemsSource="{Binding Path=StationConfigurations}" SelectionMode="Single"  SelectedItem="{Binding SelectedConfiguration}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
    <DataGrid.Columns>
    <DataGridTextColumn MinWidth="100" Width="Auto" Header="Roll">
        <DataGridTextColumn.Binding>
        <MultiBinding Converter="{StaticResource AngleMultiValueConverter}" ValidatesOnExceptions="True" StringFormat="f" Mode="TwoWay">
            <Binding Path="Roll" FallbackValue="-99.99"/>
            <Binding Source="{x:Static unitTypes:AngleSelectionType.Degrees}"/>
            <Binding ElementName="AngleSelectionControl" Path="DisplayValueType"/>
            <Binding ElementName="AngleSelectionControl" Path="ValueFormat"/>
        </MultiBinding>
        </DataGridTextColumn.Binding>
    </DataGridTextColumn>
    <DataGridTextColumn MinWidth="100" Width="Auto" Header="Roll2" Binding="{Binding Roll, ValidatesOnExceptions=True, StringFormat=f}"></DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

1 个答案:

答案 0 :(得分:1)

尝试将第二个绑定的Path属性设置为'。':

<Binding Path="." Source="{x:Static unitTypes:AngleSelectionType.Degrees}"/>