[英]In App Search in wp7 app
I've a listbox which has many items. 我有一个包含很多项目的列表框。 I'm trying to create a search bar so that a user can type in what he is looking for and my listbox displays only those items relevant to what the user has typed in textbox.
我试图创建一个搜索栏,以便用户可以键入他要查找的内容,而我的列表框仅显示与用户在文本框中键入的内容相关的那些项目。 I'm new to wp7
我是wp7的新手
First you should use MVVM
for proper Layout
updating. 首先,您应该使用
MVVM
进行正确的Layout
更新。 Then use additional property and bind it to TextBox
. 然后使用其他属性并将其绑定到
TextBox
。 When property was updated - rise another property changed event to update ListBox
( FirePropertyChanged("FooList");
in snippet). 更新属性后-引发另一个属性更改事件以更新
ListBox
( FirePropertyChanged("FooList");
)。
public class Foo
{
public string Name { get; set; }
}
in ViewModel
: 在
ViewModel
:
public string SearchCriteria
{
get
{
return searchCriteria;
}
set
{
serchCriteria = value;
RaisePropertyChanged("SearchCriteria");
RaisePropertyChanged("FooList");
}
}
private List<Foo> fooList;
public List<Foo> FooList
{
get
{
return fooList.Where(x => x.Name.Contains(searchCriteria));
}
}
in Xaml
: 在
Xaml
:
<TextBox x:Name="searchText" Text={Binding SearchCriteria, Mode=TwoWay} />
<ListBox x:Name="elementsList" ItemsSource={Binding FooList, Mode=TwoWay}>
<ListBox.ItemTemplate>
...
</ListBox.ItemTemplate>
</ListBox>
MVVM
pattern:
MVVM
模式:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.