我安装了2010年2月的WPF工具包,因为我对评估AutoCompleteBox控件感兴趣,而且我的成功非常有限.我可以让控件工作,但是一旦我尝试在XAML中设置它的任何属性,我得到以下内容:
未知的构建错误,'无法解析对程序集的依赖关系'WPFToolkit,Version = 3.5.40128.1,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'因为它尚未预加载.使用ReflectionOnly API时,必须通过ReflectionOnlyAssemblyResolve事件按需预加载或加载相关的程序集.
我一直在一个新的解决方案的空白WPF窗口上测试它.我猜我只是缺少一个引用或者其他东西......这是XAML(我没有在.xaml.cs中添加任何东西):
<Window x:Class="WpfToolkitApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
Title="Window1" Height="300" Width="300">
<Grid>
<toolkit:AutoCompleteBox Height="25"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我添加的唯一引用是System.Windows.Controls.Input.Toolkit.有任何想法吗?
我正在使用WPF工具包AutoCompleteBox,其itemsSource是一个数百万个对象的列表.
AutoCompleteBox是否用于搜索后台线程,如果不是,我该如何进行.
我的问题:
我列出了118个化学元素名称.我希望制作一个文本框,当我输入它时会抛出一个带有名字提示的下拉菜单.我在winforms中创建了这个文本框,但这是一块蛋糕,但是我在wpf中制作它的努力是徒劳的.我尝试过扩展的wpf工具包,nimgoble和其他一些自动完成文本框库.到目前为止死胡同...我也是wpf的新手,所以也许我错过了这些libs的东西?我不能让他们列出我的项目,有些甚至不会显示下拉菜单.
继承人我想要的:
这是我最终实现它的方式:
所以我通过使用文本框和列表框的组合解决了这个问题.在文本框用户类型和更改(文本框已更改事件)的位置,它检查列表中的匹配项,该列表包含所有118个元素的名称,并显示列表框内输入的文本的匹配项.这是代码:
private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
listBox.Items.Clear();
if (textBox.Text.Trim() != "")
{
string regexPattern = (textBox.Text.ToString()) + "\\w*";
regexPattern = char.ToUpper(regexPattern[0]) + regexPattern.Substring(1); //prvo slovo veliko
Match match = Regex.Match(ElementNames.allElements, regexPattern);
while (match.Success && match.Value != "")
{
listBox.Items.Add(match.Value.ToString());
listBox.Visibility = Visibility.Visible;
match = match.NextMatch();
}
}
if (listBox.Items.IsEmpty || listBox.Items.Count == 119)
{
listBox.Visibility = Visibility.Collapsed;
if (listBox.Items.Count == 119) listBox.Items.Clear();
}
HighlightElementsOnTable();
OtherButtonsHighlight();
BringBackColors();
}
Run Code Online (Sandbox Code Playgroud) 我想限制WPF AutoCompleteBox(wpf工具包控件)只从建议列表中选择一个项目.它不应该允许用户键入他们想要的任何内容.
有人可以建议我如何实现这个?任何示例代码都表示赞赏.
我正在使用wpf工具包AutoCompleteBox,我已经设置了Item模板.问题:弹出列表中的项目看起来很棒,但它对上面的文本框(选定项目)没有生效.

XAML:
<Controls:AutoCompleteBox x:Name="x" ItemFilter="SearchPerson" Margin="20">
<Controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<Rectangle Width="10" Height="10" Fill="LightGreen"/>
<TextBlock Text="{Binding Age}" />
</StackPanel>
</DataTemplate>
</Controls:AutoCompleteBox.ItemTemplate>
</Controls:AutoCompleteBox>
Run Code Online (Sandbox Code Playgroud)
代码背后:
public partial class MainWindow : Window
{
public List<Person> Persons { get; set; }
public MainWindow() {
InitializeComponent();
Persons = new List<Person> {
new Person{Name = "Jhon",Age=35},
new Person{Name = "Kelly",Age=40}};
x.ItemsSource = Persons;
DataContext = this;
}
bool SearchPerson(string search, object value) {
return (value as Person).Name.ToLower().Contains(search);
}
}
public class Person …Run Code Online (Sandbox Code Playgroud) 我正在尝试在文本框中创建一个自动完成功能,但结果应该来自我的SQL数据库.
这是我正在尝试配置的代码:
index.php:
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = [
"autocomplete.php"; ];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
编辑:我改变了变量availableTags的内容并将其变为var availableTags = <?php include('autocomplete.php') ?>;
变量availableTags是单词的来源,所以我尝试更改它,而是将文件名放在从我的数据库中取出单词的位置.
这是我的autocomplete.php文件:
<?php
include('conn.php');
$sql="SELECT * FROM oldemp";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
while($row=mysqli_fetch_array($result)) …Run Code Online (Sandbox Code Playgroud) 在AutoCompleteBox的源代码中(可从Microsoft下载),我发现了以下内容:
/// <summary>
/// Called when the selected item is changed, updates the text value
/// that is displayed in the text box part.
/// </summary>
/// <param name="newItem">The new item.</param>
private void OnSelectedItemChanged(object newItem)
{
string text;
if (newItem == null)
{
text = SearchText;
}
else
{
text = FormatValue(newItem, true);
}
// Update the Text property and the TextBox values
UpdateTextValue(text);
// Move the caret to the end of the text box
if (TextBox != null && …Run Code Online (Sandbox Code Playgroud) 这不是一个问题,但我对问题的答案我无法在互联网上找到解决方案.
我在MVVM Silverlight应用程序中清除SearchText时遇到问题.我可以清除SelectedItem和Text,但是SearchText被遗忘了.它是只读的,不能通过绑定更改.
示例:带有国家/地区列表的AutoCompleteBox.当用户想要进入澳大利亚时,他们进入'au'此时该列表与奥地利和澳大利亚一起出现.然后用户可以选择澳大利亚并继续前进.在编辑结束时,他们点击"保存"按钮.此时,您可能希望清除数据以输入新数据.
即使您绑定了SelectedItem和Text属性,并将它们分别设置为'null'和string.Empty,SearchText属性仍然存在,AutoCompleteBox将不会清除,但将包含'au'.
我遇到了AutoCompleteBox过滤问题.
它似乎正在重新修改前一个过滤器.
例如,我输入'A',它返回1项.我删除'A'并输入'Z',它应返回1项.
问题是它返回'A'过滤器加'Z'的结果,我删除'Z'并输入'S',它带回2个项目,现在它显示所有3个过滤器的结果.
难道我做错了什么?
stockTypes.Add(new StockTypeDTO() { Description = "Steel Coil", StockCode = "SC" });
stockTypes.Add(new StockTypeDTO() { Description = "Palletised Steel Coil", StockCode = "PS" });
stockTypes.Add(new StockTypeDTO() { Description = "ZZZZZ", StockCode = "ZZ" });
<input:AutoCompleteBox x:Name="testauto" FilterMode="Custom">
<input:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<ContentPresenter Content="{Binding Description}" />
</StackPanel>
</DataTemplate>
</input:AutoCompleteBox.ItemTemplate>
</input:AutoCompleteBox>
testauto.ItemsSource = this.StockTypes;
testauto.ItemFilter = (search, item) =>
{
StockTypeDTO stockType = item as StockTypeDTO;
if (stockType != null)
{
string filter = search.ToUpper(CultureInfo.InvariantCulture);
return (stockType.StockCode.ToUpper(CultureInfo.InvariantCulture).Contains(filter)
|| stockType.Description.ToUpper(CultureInfo.InvariantCulture).Contains(filter)); …Run Code Online (Sandbox Code Playgroud) 下拉列表的宽度是否可以设置为与AutoCompleteBox本身不同的值?
autocompletebox ×10
wpf ×3
c# ×2
wpftoolkit ×2
html ×1
jquery ×1
mysql ×1
php ×1
silverlight ×1
templates ×1
xaml ×1