【发布时间】:2013-04-03 06:29:32
【问题描述】:
我有一个包含 1000 多个项目的列表框。
在xml中
<ListBox
//some code here
SelectionChanged="OnSelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<controls:MyCustomItem/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在cs中
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = lb.SelectedItem as MyCustomItem;
var vm = DataContext as ViewModel;
if (vm == null) return;
foreach (var it in vm.ItemsForBinding)
{
it.IsSelected = false;
}
item .IsSelected = true;
}
在 MyCustomItem xaml 中
<UserControl
//Some code here
Style="{Binding Path=IsSelected, Converter = {StaticResource BoolToStyle}}">
<Border
</Border>
</UserControl>
Where IsSelected - 我的 ViewModel 的属性之一。转换器返回两种样式中的一种(第一个如果选中项目,第二个 - 如果没有)
总是有效,但我知道 - 这非常耗费资源,而且是错误的决定。 怎么做才对?
【问题讨论】:
-
从观点来看,主要问题是列表框中有 1000 多个项目。您真的需要列表框中的那么多项目吗?你能把它分解成多个列表框吗?
-
不,我真的需要在单个 ListBox 上显示所有具有过滤功能的项目。我找到了解决方案并发布了它。
标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-7.1.1