[英]Silver Light Data not populating in TextBoxes
I am new in Silver Light, I am having a button on datagrid with a link to open PopUp window This is how I am opening the Popup 我是Silver Light的新手,我在datagrid上有一个带有打开PopUp窗口的链接的按钮,这就是我打开Popup的方式
MyChildPage view = new MyChildPage("123");
view.Show();
and in Constructor of my Page I am getting Data from Database, This is how I am doing in MyChild Page 在我的页面构造器中,我正在从数据库中获取数据,这就是我在MyChild页面中所做的
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; }
}
and this is my XAML 这是我的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" />
but the Data is not loading in textboxes, I tried debugging the code and it is returning the Data properly, I put breakpoint on GetDataCompleted Event, The data is appearing in DatatoLoad but populating the TextBoxes,What can be the problem and how can I fix it? 但是数据没有加载到文本框中,我尝试调试代码并正确返回数据,我在GetDataCompleted事件上设置了断点,数据出现在DatatoLoad中,但填充了文本框,这可能是问题所在,我该如何解决它?
You have to bind the TextProperty
of your TextBoxes
to the property that contains the loaded data: 您必须将
TextBoxes
的TextProperty
绑定到包含已加载数据的属性:
<TextBox x:Name="DatatoLoad_Name" ...
Text="{Binding Path=DatatoLoad.Name}"/>
<TextBox x:Name="DatatoLoad_Details" ...
Text="{Binding Path=DatatoLoad.Details}"/>
And you have to make sure that your data object is set as the DataContext of your view: 并且必须确保将数据对象设置为视图的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 };
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.