Search code examples
c#wpfdatagridmultibinding

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

Solution

  • Try to set the Path property of the second binding to '.':

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