自动完成框无法清除键盘笔触 [英] Autocompletebox doesn't clear keyboard strokes
问题描述
在我的一个应用程序中,我使用的是wpf工具包中的WPF自动填充框。我正在通过MVVM模式实现它。绑定工作正常,但是尝试清除自动完成框的内容时我遇到了一个小问题。将viewmodel中的bound属性设置为null,仅部分清除文本(不会清除通过键盘输入的所有文本-即如果我在获取所有城市时输入CH并选择Chicago,并将bound属性设置为null,则CH
In an application of mine, I'm using the WPF autocomplete box from the wpf toolkit. I'm implementing it via the MVVM pattern. The binding works fine, but I have a small problem when trying to clear the content of the autocompletebox. Setting the bound property in the viewmodel to null, clears the text only partially (all text entered via the keyboard is not cleared - i.e. if I enter CH when fetching all the cities and select Chicago and the set the bound property to null, the CH is not being cleared , the rest ICAGO is.)
XAML看起来像这样:
The XAML looks like this:
<my:AutoCompleteBox Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Left"
Margin="0,6,0,0"
Name="acTown"
SelectedItem="{Binding NewTown, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ValueMemberBinding="{Binding Converter={StaticResource TownConverter}}"
Populating="Populating"
VerticalAlignment="Top"
Height="Auto"
</my:AutoCompleteBox>
在视图模型中清除框的方法是:
The method in the viewmodel to clear the box is:
public void ClearTown()
{
NewTown = null;
OnPropertyChanged("NewTown");
}
我不知道代码有什么问题,或者这仅仅是自动完成框中的错误?
I can't figure out what's wrong with the code, or is this just a bug in the autocompletebox?
经过广泛研究,我发现了这篇文章:如何使用MVVM清除Silverlight AutoCompleteBox SearchText ,但没有提供解决方案。
After extensive research, I found this article: How do you clear the Silverlight AutoCompleteBox SearchText using MVVM, but it does not offer a solution. There seems to be a SearchText property on the AutoCompleteBox that is readonly and cannot have a setter
推荐答案
最后得到了它,但似乎在AutoCompleteBox上有一个SearchText属性,该属性是只读的,不能有设置器。如果有人感兴趣,解决方案是在ClearTown函数中将 NewTown = null
更改为 NewTown = new NewTown()
Finally got it. If anyone's interested, the solution is to simply change NewTown = null
to NewTown = new NewTown()
in the ClearTown function.
这篇关于自动完成框无法清除键盘笔触的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!