我曾經使用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>;
}
我想從可觀察集合中獲取客戶名稱和客戶電子郵件。
我很困惑。這些值是不是出現在列表框中,或者你是否想要獲得別的東西? – Josh
@Josh,我想獲取列表框內的值,因爲它是textblock數據綁定,所以我不能使用正常的字符串name = textblock.text .. –