银光数据不填充在文本框

本文关键字:文本 填充 数据 | 更新日期: 2023-09-27 18:17:41

我是新的银光,我在数据网格上有一个打开弹出窗口的链接按钮这就是我如何打开弹出窗口

MyChildPage view = new MyChildPage("123");
                view.Show();

和在我的页面的构造函数中,我从数据库中获取数据,这就是我在MyChild Page

中所做的
public MyChildPage(string id)
{
    InitializeComponent();
    LoadData(id);
    client.GetDataCompleted +=
        new EventHandler<GetDataCompletedEventArgs>(client_GetDataCompleted);
}
private void LoadData(string Id)
{
    client.GetLeadsforUnResolvedAsync(policyId);
}
void client_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
{
    if (e.Error == null)
    {
        if (e.Result != null)
        {
            DatatoLoad = e.Result;
        }
    }
}
private MyClass _data;
public MyClass DatatoLoad
{
    get { return _data; }
    set { _data = value; }
}

这是XAML

<TextBlock Text="Name" Style="{StaticResource FieldHeadingStyle}"
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Margin="12,29,0,0" Width="67" />
<TextBox x:Name="DatatoLoad_Name"
    VerticalAlignment="Top" HorizontalContentAlignment="Stretch"
    Margin="12,51,100,0" TabIndex="4"/>
<TextBox x:Name="DatatoLoad_Details"
    HorizontalContentAlignment="Stretch" Margin="12,98,100,0"
    TabIndex="4" VerticalAlignment="Top" />

但是数据没有在文本框中加载,我试着调试代码,它正在正确地返回数据,我把断点放在getdataccompleted事件上,数据出现在DatatoLoad中,但填充文本框,问题是什么,我该如何修复它?

银光数据不填充在文本框

您必须将TextBoxesTextProperty绑定到包含加载数据的属性:

<TextBox x:Name="DatatoLoad_Name" ...
    Text="{Binding Path=DatatoLoad.Name}"/>
<TextBox x:Name="DatatoLoad_Details" ...
    Text="{Binding Path=DatatoLoad.Details}"/>

你必须确保你的数据对象被设置为视图的DataContext:

public class MyViewModel
{
    private MyClass _data;
    public MyClass DatatoLoad
    {
        get { return _data; }
        set { _data = value; }
    }
}
...
if (e.Result != null)
{
    this.DataContext = new MyViewModel { DatatoLoad = e.Result };
}