案子:
public class customer
{
public string Adress { get; set; }
}
xml:
<Grid x:Name="LayoutRoot" Background="White" > <StackPanel> <TextBox Text="{Binding Adress}"/> </StackPanel> </Grid>
。CS
public MainPage() { InitializeComponent(); LayoutRoot.DataContext = new customer() { Adress = "Some Adr" }; }
所以问题是,在后面的代码中。如何获取绑定(地址)的属性(字符串)。我需要它来访问 customer.adress 作为属性,分配另一个变量。(在这种情况下,当事件发生时。例如,在 this.Loaded 发生之后。)
所以我得到了UIElement
(发件人),我可以从它的DataContext
.
简而言之,如何获取绑定对象的属性名称。(绑定对象很容易找到,我只是DataContext
用来获取客户,但是我在哪里可以得到属性的名称?在发件人的 xaml(例如名称)中)
(如果需要访问客户内部的“地址”,我计划使用反射)但是如何获取 textBox 中的文本绑定到的属性的“名称”。