question

JimJupiter-5178 avatar image
0 Votes"
JimJupiter-5178 asked JimJupiter-5178 answered

The bidirectional binding requires “Path” or “XPath” exception

Hi

exception occurs when I leave a cell in my datagrid - but I didn't know where to find the error

 <DataGrid ItemsSource="{Binding}" ...
    
    
 <DataGrid.Columns>
                 <DataGridTextColumn Width="40" Header="ID" Binding="{Binding ID}" >
                     <DataGridTextColumn.ElementStyle>
                         <Style TargetType="TextBlock">
                             <Setter Property="HorizontalAlignment" Value="Center" />
                         </Style>
                     </DataGridTextColumn.ElementStyle>
                 </DataGridTextColumn>
    
                 <DataGridTextColumn Width="250" Header="Name" Binding="{Binding Name}" >
                     <DataGridTextColumn.ElementStyle>
                         <Style TargetType="TextBlock">
                             <Setter Property="HorizontalAlignment" Value="Center" />
                         </Style>
                     </DataGridTextColumn.ElementStyle>
                 </DataGridTextColumn>


My xaml looks like this ... and this is code behind


   InitializeComponent();
     dGrid.DataContext = DT.Datatable;

Any Idea?

dotnet-csharpwindows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered

I used your code in xmal and the background code uses the following code . Exception does not occur when I leave a cell in my datagrid. Did I do something less or is it different from yours? Please show me more relevant steps and codes to reproduce and analyze the problem.
The code of xaml is as follows:

 <Grid>
         <DataGrid x:Name="dGrid" ItemsSource="{Binding}" AutoGenerateColumns="False"  >
             <DataGrid.Columns>
                 <DataGridTextColumn Header="ID" Width="80" Binding="{Binding ID}"  >
                     <DataGridTextColumn.ElementStyle>
                         <Style TargetType="TextBlock">
                             <Setter Property="HorizontalAlignment" Value="Center" />
                         </Style>
                     </DataGridTextColumn.ElementStyle>
                 </DataGridTextColumn>
                 <DataGridTextColumn Header="Name" Width="80" Binding="{Binding Name}">
                     <DataGridTextColumn.ElementStyle>
                         <Style TargetType="TextBlock">
                             <Setter Property="HorizontalAlignment" Value="Center" />
                         </Style>
                     </DataGridTextColumn.ElementStyle>
                 </DataGridTextColumn>
             </DataGrid.Columns>
         </DataGrid>
   </Grid>

The code of xaml.cs is as follows:

 using System.Data;
 using System.Windows;
 namespace BidirectionalBindingException
 {
   public partial class MainWindow : Window
   { 
     public MainWindow()
     {
       InitializeComponent();
       dGrid.DataContext = GetDummyData();
     }
     private static DataTable GetDummyData()
     {
       DataTable dt = new DataTable();
       DataColumn ID = new DataColumn("ID", typeof(int));
       dt.Columns.Add(ID);
       dt.Columns.Add("Name", typeof(string));
       dt.PrimaryKey = new DataColumn[] { ID };
       dt.Rows.Add(1, "Name1");
       dt.Rows.Add(2, "Name2");
       return dt;
     }
   }
 }

The result is shown in the figure:
116734-22.gif




22.gif (51.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JimJupiter-5178 avatar image
0 Votes"
JimJupiter-5178 answered

Aaarg - I just wanted to post more - then the error blinks in my eyes :))


Binding line in column 3

<DataGridTextColumn Width="250" Header="Visual" Binding="{Binding VS}" >


DT.Columns.Add("Vs", typeof(string));

Mistyping Name


thanks for your help

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.