获取RadAutoCompleteBox的文本 [英] Get text of RadAutoCompleteBox

查看:154
本文介绍了获取RadAutoCompleteBox的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#中的RadControls Q1 2013获取RadAutoCompleteBox的文本?

How can I get the text of a RadAutoCompleteBox using RadControls Q1 2013 in C#?

autoCompleteBox.SelectedItem返回"ServerCrafterTelerikWPF.Command".

修改1: 这是我的XAML:

Edit 1: Here's my 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中的文本.

And I don't have any C# code. I just want, when a button is pressed, to get the text that is in the 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...
                // ...
                // ...
            };
    }
}

推荐答案

您应该从SelectedItem属性中获取它.将其转换为您的班级,然后从MyClass.ACommand

You should take it from the SelectedItem property. Cast it to your class and then get it from MyClass.ACommand

而且我建议在ViewModel中将SelectedItemMode=TwoWay绑定可以有很大帮助.

And I suggest binding SelectedItem with Mode=TwoWay in your ViewModel can help a lot.

只需将一个成员添加到正在实现Command的ViewModel中,例如:

Just add a Member to ViewModel which is implementing Command like:

private Command _SelectedItem;

public Command SelectedItem 
{ 
   //get set with INotifyPropertyChanged 
}

然后从xaml中:绑定RadAutoCompleteBox的SelectedItem属性,例如:

Then from the xaml: Bind RadAutoCompleteBox's SelectedItem Property like:

SelectedItem="{Binding SelectedItem, Mode=TwoWay}"

这篇关于获取RadAutoCompleteBox的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆