[英]WPF ComboBox Selected Item to String
i´ve got a combobox and im trying to set either the x:Name or the content of the selected comboItem (Both is okay, i´ll take the easier one) to an list. 我有一个组合框,我试图将x:Name或选定的comboItem的内容(都可以,我会更简单的一个)设置到列表中。 But i allways just geht things like this: System.Window.Controls.StackPanel or System.Window.Controls.Comboboxitem..
但是我总是像这样:System.Window.Controls.StackPanel或System.Window.Controls.Comboboxitem ..
i tried to do it in many ways, so here s what i have right now: 我试图通过多种方式做到这一点,所以这就是我现在所拥有的:
sc.BC = ((ComboBoxItem)comboBox.SelectedItem).Content.ToString();
and in Xaml the list looks like this: 在Xaml中,列表如下所示:
<ComboBox x:Name="comboBox" SelectedValuePath="Content" IsEnabled="True" HorizontalAlignment="Left" Height="23" Margin="241,21,0,0" VerticalAlignment="Top" Width="120">
<ComboBoxItem IsSelected="True" x:Name="wertwret">
<StackPanel Orientation="Horizontal">
<TextBlock Background="White" >---</TextBlock>
<TextBlock Text=" item1"/>
</StackPanel>
</ComboBoxItem>
can anybody help me ? 有谁能够帮助我 ? thanks
谢谢
If the name of ComboBoxItem
is what you need, then just: 如果您需要
ComboBoxItem
的名称,则只需:
sc.BC = ((ComboBoxItem)comboBox.SelectedItem).Name;
"--- item1" is compound content of two UI elements. “ --- item1”是两个UI元素的复合内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.