【发布时间】:2013-03-31 10:51:42
【问题描述】:
如何在 C# 中使用 RadControls Q1 2013 获取 RadAutoCompleteBox 的文本?
autoCompleteBox.SelectedItem 返回"ServerCrafterTelerikWPF.Command"。
编辑 1: 这是我的 XAML:
<telerik:RadAutoCompleteBox x:Name="txtboxCommand" ItemsSource="{Binding Commands, Source={StaticResource ViewModel}}"
DisplayMemberPath="ACommand" AutoCompleteMode="Append" HorizontalAlignment="Left"
telerik:StyleManager.Theme="Modern" Margin="280,405,0,0"
VerticalAlignment="Top" Width="330" Height="30" KeyDown="txtboxCommand_KeyDown"/>
而且我没有任何 C# 代码。我只想在按下按钮时获取 RadAutoCompleteBox 中的文本。
编辑 2:
这是我的collection:
public class Command
{
public string ACommand { get; set; }
}
/// <summary>
/// A view model for MainWindow.xaml
/// </summary>
public class ViewModel
{
public ObservableCollection<Command> Commands { get; set; }
public ViewModel()
{
Commands = new ObservableCollection<Command>()
{
new Command() {ACommand = "stop "},
// Other commands...
// ...
// ...
};
}
}
【问题讨论】:
-
请发布您的
XAML和Code。 -
@Haritha 编辑了问题。
-
您尚未向我们展示如何获取 RadAutoCompleteBox 控件的选定项。请张贴代码。
-
我想我
got你的问题。问题应该是你得到了选定的项目as a string。但它should是Command class 的类型。 (实际上应该是collection of Command类的类型,因为RadAutoCompleteBox 可以有multiple selected items。)请看我的回答。
标签: c# wpf xaml telerik rad-controls