"Two-way binding requires Path or XPath" 尝试编辑 DataGrid 列时
"Two-way binding requires Path or XPath" when attempting edit a DataGrid column
我有一个 DataGrid,我在其中一个列中执行 MultiBinding。只是一些背景知识——我有一个控件 (AngleSelectionControl),用户可以选择要在数据网格中显示的单位(度或弧度)。使用下面的代码,Roll2 列显示存储在模型中的值(度)。滚动列显示给定所选单位(度或弧度)的正确值。一切正常。我还可以更改 Roll2 列值,Roll 列会更新并以选定的单位显示。但是,当我尝试编辑 Roll 列(在单元格中双击)时,调试器显示异常 "Two-way binding requires Path or 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>
尝试将第二个绑定的 Path
属性 设置为 '.':
<Binding Path="." Source="{x:Static unitTypes:AngleSelectionType.Degrees}"/>
我有一个 DataGrid,我在其中一个列中执行 MultiBinding。只是一些背景知识——我有一个控件 (AngleSelectionControl),用户可以选择要在数据网格中显示的单位(度或弧度)。使用下面的代码,Roll2 列显示存储在模型中的值(度)。滚动列显示给定所选单位(度或弧度)的正确值。一切正常。我还可以更改 Roll2 列值,Roll 列会更新并以选定的单位显示。但是,当我尝试编辑 Roll 列(在单元格中双击)时,调试器显示异常 "Two-way binding requires Path or 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>
尝试将第二个绑定的 Path
属性 设置为 '.':
<Binding Path="." Source="{x:Static unitTypes:AngleSelectionType.Degrees}"/>