DataGrid - “双向绑定需要 Path 或 XPath". [英] DataGrid - "Two-way binding requires Path or XPath."

查看:33
本文介绍了DataGrid - “双向绑定需要 Path 或 XPath".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 DataGrid 上显示我的对象数据库

I would like to display on DataGrid my object database

public class Student
{
public string Imie { get; set; }
public string Nazwisko { get; set; }
string Numer { get; set; }

internal List<Telefon> Telefony { get; set; }
internal Adres Adres { get; set; }
}

AdresTelefon 类中,我显然有一些额外的字段.

In Adres and Telefon class I have obviously some extra fields.

我的 XAML:

<DataGrid Name="dataGrid" ItemsSource="{Binding Student}" AutoGenerateColumns="False" CellEditEnding="dataGrid_CellEditEnding" CurrentCellChanged="dataGrid_CurrentCellChanged" PreviewKeyDown="dataGrid_PreviewKeyDown">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Imie"        Binding="{Binding Imie}"/>
            <DataGridTextColumn Header="Nazwisko"    Binding="{Binding Nazwisko}"/>
            <DataGridTextColumn Header="Numer"       Binding="{Binding Numer}"/>
            <DataGridTextColumn Header="Ulica"       Binding="{Binding Adres.Ulica}"/>
            <DataGridTextColumn Header="KodPocztowy"       Binding="{Binding  Adres.KodPocztowy}"/>
            <DataGridTextColumn Header="Miasto"       Binding="{Binding Adres.Miasto}"/>
            <DataGridTextColumn Header="Tel. Numer"       Binding="{Binding Telefon.Numer}"/>
            <DataGridTextColumn Header="Tel. Operator"       Binding="{Binding Telefon.Operator}"/>
        </DataGrid.Columns>
    </DataGrid>

我可以轻松获取和设置 ImieNazwiskoNumer 字段,但是当我尝试设置 Ulica 的值时(Adres 类中的字段)编译器给了我这个异常:

I can easily get and set Imie, Nazwisko and Numer fields but when i'm trying to set value of Ulica (field in Adres class) compiler gives me this exception:

InvalidOperationException was unhandled
Two-way binding requires Path or XPath.

感谢您的帮助.

推荐答案

问题是因为绑定成员名称中的 .(dot).请参阅:绑定到 C# 中 DataTable 中包含句点的字段/WPF

The problem is because of the .(dot) in the binding member name. Please refer to: Binding to fields containing a period in DataTable in C#/WPF

这篇关于DataGrid - “双向绑定需要 Path 或 XPath".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆