如何在 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:
这是我的收藏
:
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...
// ...
// ...
};
}
}
最佳答案
您应该从 SelectedItem
属性中获取它。将它转换到您的类(class),然后从 MyClass.ACommand
我建议在您的 ViewModel 中将 SelectedItem
与 Mode=TwoWay
绑定(bind)会有很大帮助。
只需将一个成员添加到 ViewModel,它正在执行如下命令:
private Command _SelectedItem;
public Command SelectedItem
{
//get set with INotifyPropertyChanged
}
然后从 xaml 中:像这样绑定(bind) RadAutoCompleteBox 的 SelectedItem 属性:
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
关于c# - 获取 RadAutoCompleteBox 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15894646/