我使用listbox.itemsource作为我的e.Result。
<ListBox Height="476" HorizontalAlignment="Left" Margin="11,17,0,0" Name="ListBox1" VerticalAlignment="Top" Width="434" Foreground="#FFF5F5F1" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Height="40" HorizontalAlignment="Left" Margin="8,24,10,0" Name="txtBlockCustName" Text="{Binding CustName, Mode=OneWay}" VerticalAlignment="Top" FontSize="26" />
<TextBlock Height="40" HorizontalAlignment="Left" Margin="8,24,0,0" Name="txtBlockCustEmail" Text="{Binding CustEmail, Mode=OneWay}" VerticalAlignment="Top" FontSize="26" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我怎样才能获得数据绑定值?
void proxy_FindProfileCompleted(object sender, FindProfileCompletedEventArgs e)
{
ListBox1.ItemsSource = e.Result;
ObservableCollection<Customer> Customers = this.ListBox1.ItemsSource as ObservableCollection<Customer>;
}
我想从可观察的集合中获取客户名称和客户电子邮件。
答案 0 :(得分:1)
我不明白这是否是你需要的,但试一试:
void proxy_FindProfileCompleted(object sender, FindProfileCompletedEventArgs e)
{
ListBox1.ItemsSource = e.Result;
ObservableCollection<Customer> Customers =
this.ListBox1.ItemsSource as ObservableCollection<Customer>;
foreach(Customer cust in Customers)
{
// You can get cust.CustName
// and you can get cust.CustEmail
}
}
答案 1 :(得分:0)
您可以从查看课程CollectionViewSource
开始。这会跟踪当前项目(您可能必须在列表框绑定上IsSynchronizedWithCurrentItem=true
)。你可以绑定到它并传递它。
如果这不能回答你的问题,我会尝试提出一个更详细的例子。