Silverlight 中的自动完成框文本
我无法让 System.Windows.Controls.Input 中的自动完成框按我的意愿工作。当我开始输入显示过滤列表的下拉部分时,它不显示我要绑定的属性,而是显示类名称。
因此,在下面的示例中,当我输入 my - 而不是显示“我的名字”时,它显示 MyNamespace.Person。但是,当我从自动完成列表中选择该项目时,它会在文本框中显示 FullName 属性。我确信我只是在某个地方缺少一个简单的自动完成框属性,但我看不到它。
示例代码:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return string.Format("{0} {1}", FirstName, LastName); }
}
}
在我后面的 xaml 代码中,我创建了一些 Person 对象并将它们存储在一个列表中,并将该列表绑定到自动完成框
List<Person> people = new List<Person>();
people.Add(new Person { FirstName = "My", LastName = "Name" });
people.Add(new Person { FirstName = "Fernando", LastName = "Torres" });
acbNames.ItemsSource = people;
My xaml:
<my:AutoCompleteBox Name="acbNames" ValueMemberPath="FullName" />
/* 输入“my”后,自动完成显示“MyNamespace.Person”而不是“My”名称”,但从列表中选择项目后显示“我的名字”*/
I'm having trouble getting the autocomplete box in System.Windows.Controls.Input working as I wish. When I start typing the dropdown section that displays the filtered list doesn't show the property that I'm binding to, it shows the class name instead.
So in the example below, when I type in my - instead of showing 'My Name' it shows MyNamespace.Person. However, when I select the item from the autocomplete list, it displays the FullName property in the textbox. I'm sure I'm just missing a simple autocomplete box property somewhere but I can't see it.
Example code:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return string.Format("{0} {1}", FirstName, LastName); }
}
}
In my xaml code behind I create some Person objects and store them in a list and bind that list to an autocomplete box
List<Person> people = new List<Person>();
people.Add(new Person { FirstName = "My", LastName = "Name" });
people.Add(new Person { FirstName = "Fernando", LastName = "Torres" });
acbNames.ItemsSource = people;
My xaml:
<my:AutoCompleteBox Name="acbNames" ValueMemberPath="FullName" />
/* after entering 'my', auto complete displays 'MyNamespace.Person' instead of 'My Name', but displays 'My Name' after selecting the item from the list */
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,我需要对 AutoCompleteBox 的下拉部分使用 ItemTemplate,因此它的 xaml 现在如下所示:
It turns out I need to use an ItemTemplate for the dropdown part of the AutoCompleteBox, so the xaml for it would now be as follows:
是的,您的问题是因为您没有放置项目模板。
但是,如果您放置项目模板但仍然遇到问题,请阅读 Sandro 所写的内容。
我有同样的问题。我使用控件样式的静态资源解决了这个问题,
这是我使用的样式:
如果我不使用此样式,我的自定义项将无法正确显示,因为我在数据项中配置,而是显示类名称。
分享|编辑
这也适用于我,但仅当我应用工具包中的一些自定义主题样式时。
中的主题时,还有一些其他解决方法
当您使用工具包Best、
debarisi
Yes, your problem was because you didn't put item template.
But if you put item template and still got problem read what Sandro has wroted.
I had same problem. I solved it using a Static resource for the Control Style
This is the style i used:
If I don't use this style my Customs Item are not displayed correctly as I configure in DataItem, instead it show the Class name.
share|edit
This works for me too but only when i applied some custom theme style from toolkit.
There are some other workarounds when you use theme from toolkit
Best,
debarisi
我有同样的问题。我使用控件样式的静态资源解决了这个问题,
这是我使用的样式:
如果我不使用此样式,我的自定义项将无法正确显示,因为我在数据项中配置,而是显示类名称。
I had same problem. I solved it using a Static resource for the Control Style
This is the style i used:
If I don't use this style my Customs Item are not displayed correctly as I configure in DataItem, instead it show the Class name.