简体   繁体   中英

“Two-way binding requires Path or XPath” when attempting edit a DataGrid column

I have a DataGrid where I am doing MultiBinding in one of the columns. Just a little background--I have a control (AngleSelectionControl) which the user is selecting the units (degrees or radians) for which to display in the data grid. With the code below, the Roll2 column is displaying the value as it is stored in the model (degrees). The roll column is displaying the correct value given the selected unit (degrees or radians). That all works. I can also change the Roll2 column value and the Roll column is updated and displayed in selected units. But, when I attempt to edit the Roll column (double clicking in cell), the debugger displays the exception saying "Two-way binding requires Path or XPath". What am I missing?

<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}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM