- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是,如果我在 ValueMemberPath 中有具有相同值的对象,那么 AutoCompleteBox 在选择正确的项目后选择第一个项目。我已将 SelectedItem 绑定(bind)到一个属性,如果有多个项目具有相同的值,我可以看到它会被触发两次。
我已将我的 AutoCompleteBox 绑定(bind)到 Person 对象的 ObservableCollection。
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
public string FullName
{
get
{
return Name + " - " + ID;
}
}
}
我的 XAML 如下所示:
<StackPanel>
<inputtoolkit:AutoCompleteBox x:Name="autoCompleteBox" ValueMemberPath="Name" ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson, Mode=TwoWay}">
<inputtoolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FullName}" FontSize="14" FontWeight="Bold"></TextBlock>
</DataTemplate>
</inputtoolkit:AutoCompleteBox.ItemTemplate>
</inputtoolkit:AutoCompleteBox>
<TextBlock x:Name="textBlock" Text="{Binding SelectedPerson.ID}"></TextBlock>
</StackPanel>
我的 Window_Loaded 看起来像这样:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Persons = new ObservableCollection<Person>();
Persons.Add(new Person() { ID = 1, Name = "Person" });
Persons.Add(new Person() { ID = 2, Name = "Person" });
Persons.Add(new Person() { ID = 3, Name = "Person" });
Persons.Add(new Person() { ID = 4, Name = "Person" });
autoCompleteBox.DataContext = this;
textBlock.DataContext = this;
}
当我写“Per”时,下拉列表中将显示 4 个项目。现在,当我选择第四个时,它会被选中并且绑定(bind)会更新。然而,它然后回到第一个项目。这是错误还是预期行为,有人可以帮我解决这个问题吗?
最佳答案
我也遇到了同样的问题。我还没有尝试过,但我找到了这个链接,它看起来有解决方案。
http://www.yumasoft.com/node/45
编辑
我刚刚确认这确实有效。
对于询问用户如何分辨差异的评论。 ItemTemplate 提供者比仅在 TextBox 部分中显示的更详细。这允许用户决定使用哪个记录。
关于c# - 具有多个具有相同值的项目时的 AutoCompleteBox 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5168206/
我正在为我的 WPF C# 项目创建一个用户选择 userControl。我确实为选择制作了自定义自动完成控件,但出于优化目的,我现在正在研究使用 WPF 工具包中的自动完成文本框。 因为我在数据库中
在我的一个应用程序中,我使用了 wpf 工具包中的 WPF 自动完成框。我正在通过 MVVM 模式实现它。绑定(bind)工作正常,但我在尝试清除自动完成框的内容时遇到了一个小问题。将 View 模型
我的 AutoCompleteBox 在选择更改时调用 WCF 服务,通常使用鼠标。但是,如果用户使用箭头键在选择中导航,则每个元素都会触发该事件,从而使应用程序数据密集。 按下按键时,如何防止 Au
我正在使用 WPF 工具包 AutoCompleteBox,它的 itemsSource 是一个包含数百万个对象的列表。 AutoCompleteBox 是否用于搜索后台线程,如果没有,我该如何实现。
我刚刚通过 NuGet 将 Silverlight 4 工具包添加到我的项目中。 (NuGet 包“Silverlight 工具包 - 全部”) 我在添加到我的项目的 dll 中的任何地方都找不到 A
我需要在 Silverlight 4 应用程序的 AutoCompleteBox 中强制输入大写字母。 在 TextBox 中,可以通过替换 KeyDown 事件上的 Text 属性来完成,例如:
我在 MVVM 中使用 AutoCompleteBox,我只想在用户单击项目或用户按 Enter 时执行某些操作。 但是现在,当我使用键盘上的向下\向上键时,selectedItem 属性会发生变化.
似乎有些人在 Silverlight 中更新文本 AutoCompleteBox 时遇到问题,遗憾的是我已经加入了这个行列。 我有一个像这样的名为 EditableCombo 的派生类; publ
我的问题是,如果我在 ValueMemberPath 中有具有相同值的对象,那么 AutoCompleteBox 在选择正确的项目后选择第一个项目。我已将 SelectedItem 绑定(bind)到
我的目标是允许用户点击 Tab 键和自动完成框以立即选择下拉列表中的第一项。问题是我似乎无法弄清楚如何访问第一个过滤项目。有什么想法吗? 起初我以为属性 IsTextCompletionEnabled
我在使用 AutoCompleteBox 过滤时遇到问题。 好像是想起了之前的滤镜。 例如,我输入“A”,它返回 1 个项目。我删除“A”并输入“Z”,它应该返回 1 个项目。 问题是它返回“A”过滤
我想限制 WPF AutoCompleteBox(wpf 工具包控件)仅从建议列表中选择一个项目。它不应该允许用户键入他们想要的任何内容。 有人可以建议我如何实现吗?感谢任何示例代码。 最佳答案 这是
在我的一个 WPF 项目中,我集成了 WPF Toolkit 的 AutoCompleteBox 控件。我需要此控件的自定义 Context Menu,我已使用 ContextMenu 属性添加了一个
我正在使用 wpf 工具包 AutoCompleteBox 并设置了 Item 模板。 问题:弹出列表中的项目看起来很棒,但它没有在上面的文本框(所选项目)上生效。 XAML:
刚刚安装了几天前发布的SL5和工具包。 当您将 AutoCompleteBox 的 Text 属性设置为 string.Empty 时,就会发生该错误。它会导致 AutoCompleteBox 处于错
在我的 WPF 应用程序中,我有一个 UserControl,其中有两个 AutoCompleteBox 控件。此用户控件可以在页面上多次出现。问题是,在 AutoCompleteBox 中输入内容时
我有一个装满元素的 silverlight 自动完成框。有谁知道如何突出显示列表中的第一个项目,以便在用户按下 Enter 时选择该项目并且用户不必使用鼠标? 在其他windows控件中,可以使用se
我在 wpf 窗口的两个不同选项卡中使用了两个 AutoCompleteBox 控件。 第一个选项卡中的控件工作正常。 First Control 但是第二个选项卡中的控件,数据是绑定(bind)的,
我试图在控件焦点上打开 System.Windows.Controls.AutoCompleteBox。事件触发但没有任何反应:/当我开始输入一些文本时,自动完成框工作正常。我究竟做错了什么? Aut
我想在 AutoCompleteTextView 中显示项目。它工作正常,所有下拉项目都显示。但根据我的需要,我不想在单击项目时在自动完成框中设置项目。我怎样才能做到这一点? public class
我是一名优秀的程序员,十分优秀!