C# 如何在silverlight中显示组合框中的值?
我正在努力学习表达式混合和SilverLight。我试图实现的是将所选项目从组合框输出到文本块中。有谁能给我指出正确的方向,或者告诉我如何做到这一点?这是我当前的代码:C# 如何在silverlight中显示组合框中的值?,c#,silverlight-3.0,C#,Silverlight 3.0,我正在努力学习表达式混合和SilverLight。我试图实现的是将所选项目从组合框输出到文本块中。有谁能给我指出正确的方向,或者告诉我如何做到这一点?这是我当前的代码: private void GetSubmitBtn(object sender, System.Windows.RoutedEventArgs e) { this.Message.Text = "Hello there " + this.Firstname.Text + " " + this.Surnam
private void GetSubmitBtn(object sender, System.Windows.RoutedEventArgs e)
{
this.Message.Text =
"Hello there " + this.Firstname.Text + " " + this.Surname.Text
+ ". You come from " + this.Origin.SelectedItem.ToString();
}
我认为您需要
SelectedValue
而不是SelectedItem
或
将文本块的文本绑定到combobox.text。您可以执行以下操作:
<ComboBox x:Name="Names">
<ComboBoxItem Content="John Doe" />
<ComboBoxItem Content="Jane Doe" />
<ComboBoxItem Content="Jack Black" />
<ComboBoxItem Content="Jake White" />
<ComboBoxItem Content="Kelly Blue" />
</ComboBox>
<TextBlock Text="{Binding SelectedItem.Content, ElementName=Names}" />
您可以在silverlight中将combobox的选定值显示到文本框中,如下所示:
TextBox1.Text = (cmbApplicationStatus.SelectedItem as ComboBoxItem).Content.ToString();
在这里,
cmbApplicationStatus
是您的组合框的名称,这是不正确的,因为他想在他的文本块中显示“Hello there blablabla”,而不仅仅是组合框的文本谢谢,但这不起作用。当我运行代码时,它会输出“Expression.Blend.SampleData.OriginData.Item”,谢谢,但是组合框绑定了示例数据,所以这不起作用
<UserControl.Resources>
<SampleData:SampleDataSource x:Key="SampleDataSource" d:IsDataSource="True"/>
</UserControl.Resources>
<ComboBox x:Name="Names" DataContext="{Binding Source={StaticResource SampleDataSource}}" DisplayMemberPath="FullName" ItemsSource="{Binding Collection}"/>
<TextBlock Text="{Binding SelectedItem.FullName, ElementName=Names}" />
TextBox1.Text = (cmbApplicationStatus.SelectedItem as ComboBoxItem).Content.ToString();